@getmicdrop/svelte-components 5.5.0 → 5.5.4
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/calendar/AboutShow/AboutShow.svelte +172 -172
- package/dist/calendar/Calendar/MiniMonthCalendar.svelte +782 -782
- package/dist/calendar/FAQs/FAQs.svelte +75 -75
- package/dist/calendar/MonthSwitcher/MonthSwitcher.svelte +126 -126
- package/dist/calendar/OrderSummary/OrderSummary.svelte +367 -367
- package/dist/calendar/PublicCard/PublicCard.svelte +134 -134
- package/dist/calendar/ShowCard/ShowCard.svelte +157 -157
- package/dist/calendar/ShowTimeCard/ShowTimeCard.svelte +61 -61
- package/dist/components/Layout/Grid.svelte +4 -4
- package/dist/components/Layout/Section.svelte +80 -80
- package/dist/components/Layout/Sidebar.svelte +108 -108
- package/dist/components/Layout/Stack.svelte +6 -6
- package/dist/constants/validation.js +91 -91
- package/dist/constants/validation.spec.js +64 -64
- package/dist/index.d.ts +1 -1
- package/dist/index.js +226 -226
- package/dist/patterns/data/DataGrid.svelte +45 -45
- package/dist/patterns/data/DataList.svelte +24 -24
- package/dist/patterns/data/DataTable.svelte +36 -36
- package/dist/patterns/forms/FormActions.spec.js +88 -88
- package/dist/patterns/forms/FormActions.stories.svelte +97 -97
- package/dist/patterns/forms/FormActions.svelte +46 -46
- package/dist/patterns/forms/FormGrid.svelte +33 -33
- package/dist/patterns/forms/FormSection.svelte +32 -32
- package/dist/patterns/forms/FormValidationSummary.stories.svelte +83 -83
- package/dist/patterns/forms/FormValidationSummary.svelte +33 -33
- package/dist/patterns/layout/Sidebar.svelte +39 -39
- package/dist/patterns/navigation/BottomNav.stories.svelte +117 -117
- package/dist/patterns/navigation/BottomNav.svelte +20 -20
- package/dist/patterns/navigation/Header.stories.svelte +77 -77
- package/dist/patterns/navigation/Header.svelte +193 -193
- package/dist/patterns/page/PageHeader.svelte +18 -18
- package/dist/patterns/page/PageLayout.svelte +40 -40
- package/dist/patterns/page/PageLoader.spec.js +54 -54
- package/dist/patterns/page/PageLoader.stories.svelte +137 -137
- package/dist/patterns/page/PageLoader.svelte +24 -24
- package/dist/patterns/page/SectionHeader.svelte +29 -29
- package/dist/presets/badges.js +112 -112
- package/dist/presets/buttons.js +76 -76
- package/dist/presets/index.js +9 -9
- package/dist/primitives/Accordion/Accordion.stories.svelte +75 -75
- package/dist/primitives/Accordion/Accordion.svelte +42 -42
- package/dist/primitives/Accordion/AccordionItem.svelte +95 -95
- package/dist/primitives/Alert/Alert.spec.js +170 -170
- package/dist/primitives/Alert/Alert.stories.svelte +88 -88
- package/dist/primitives/Alert/Alert.svelte +27 -27
- package/dist/primitives/Avatar/Avatar.stories.svelte +94 -94
- package/dist/primitives/Avatar/Avatar.svelte +66 -66
- package/dist/primitives/Badges/Badge.spec.js +103 -103
- package/dist/primitives/Badges/Badge.stories.svelte +86 -86
- package/dist/primitives/Badges/Badge.svelte +79 -79
- package/dist/primitives/BottomSheet/BottomSheet.spec.js +127 -127
- package/dist/primitives/BottomSheet/BottomSheet.stories.svelte +83 -83
- package/dist/primitives/BottomSheet/BottomSheet.svelte +100 -100
- package/dist/primitives/Breadcrumb/Breadcrumb.spec.js +120 -120
- package/dist/primitives/Breadcrumb/Breadcrumb.stories.svelte +23 -23
- package/dist/primitives/Breadcrumb/Breadcrumb.svelte +89 -89
- package/dist/primitives/Button/Button.spec.js +211 -211
- package/dist/primitives/Button/Button.stories.svelte +76 -76
- package/dist/primitives/Button/Button.svelte +270 -270
- package/dist/primitives/Button/ButtonSaveDemo.spec.js +48 -48
- package/dist/primitives/Button/ButtonSaveDemo.svelte +25 -25
- package/dist/primitives/Button/ButtonVariantShowcase.svelte +129 -129
- package/dist/primitives/Card.spec.js +49 -49
- package/dist/primitives/Card.stories.svelte +22 -22
- package/dist/primitives/Card.svelte +28 -28
- package/dist/primitives/Checkbox/Checkbox.stories.svelte +84 -84
- package/dist/primitives/Checkbox/Checkbox.svelte +88 -88
- package/dist/primitives/DarkModeToggle.spec.js +357 -357
- package/dist/primitives/DarkModeToggle.stories.svelte +57 -57
- package/dist/primitives/DarkModeToggle.svelte +136 -136
- package/dist/primitives/Drawer/Drawer.stories.svelte +80 -80
- package/dist/primitives/Drawer/Drawer.svelte +120 -120
- package/dist/primitives/Dropdown/Dropdown.stories.svelte +137 -137
- package/dist/primitives/Dropdown/Dropdown.svelte +14 -14
- package/dist/primitives/Dropdown/DropdownItem.svelte +80 -80
- package/dist/primitives/Icons/ArrowLeft.svelte +8 -8
- package/dist/primitives/Icons/ArrowRight.svelte +8 -8
- package/dist/primitives/Icons/Availability.svelte +14 -14
- package/dist/primitives/Icons/Back.svelte +14 -14
- package/dist/primitives/Icons/CheckCircle.svelte +6 -6
- package/dist/primitives/Icons/CheckCircleOutline.svelte +15 -15
- package/dist/primitives/Icons/ChevronLeft.svelte +4 -4
- package/dist/primitives/Icons/ChevronRight.svelte +4 -4
- package/dist/primitives/Icons/Copy.svelte +15 -15
- package/dist/primitives/Icons/Cross.svelte +5 -5
- package/dist/primitives/Icons/DownArrow.svelte +8 -8
- package/dist/primitives/Icons/ErrorCircle.svelte +6 -6
- package/dist/primitives/Icons/FacebookIcon.svelte +2 -2
- package/dist/primitives/Icons/Home.svelte +15 -15
- package/dist/primitives/Icons/Icon.spec.js +169 -169
- package/dist/primitives/Icons/Icon.stories.svelte +100 -100
- package/dist/primitives/Icons/Icon.svelte +52 -52
- package/dist/primitives/Icons/IconGallery.stories.svelte +235 -235
- package/dist/primitives/Icons/Info.svelte +7 -7
- package/dist/primitives/Icons/InstagramIcon.svelte +4 -4
- package/dist/primitives/Icons/LogoInstagram.svelte +2 -2
- package/dist/primitives/Icons/Message.svelte +15 -15
- package/dist/primitives/Icons/MoonIcon.svelte +5 -5
- package/dist/primitives/Icons/More.svelte +21 -21
- package/dist/primitives/Icons/MoreHori.spec.js +61 -61
- package/dist/primitives/Icons/MoreHori.svelte +22 -22
- package/dist/primitives/Icons/Notification.svelte +14 -14
- package/dist/primitives/Icons/Payment.svelte +14 -14
- package/dist/primitives/Icons/Profile.svelte +21 -21
- package/dist/primitives/Icons/Reload.svelte +29 -29
- package/dist/primitives/Icons/Shows.svelte +21 -21
- package/dist/primitives/Icons/Signout.svelte +21 -21
- package/dist/primitives/Icons/SunIcon.svelte +8 -8
- package/dist/primitives/Icons/TiktokIcon.svelte +2 -2
- package/dist/primitives/Icons/TwitterIcon.svelte +2 -2
- package/dist/primitives/Icons/WarningIcon.spec.js +18 -18
- package/dist/primitives/Icons/WarningIcon.svelte +5 -5
- package/dist/primitives/Input/Input.spec.js +573 -573
- package/dist/primitives/Input/Input.stories.svelte +139 -139
- package/dist/primitives/Input/Input.svelte +392 -392
- package/dist/primitives/Input/Select.spec.js +218 -218
- package/dist/primitives/Input/Select.stories.svelte +112 -112
- package/dist/primitives/Input/Select.svelte +128 -128
- package/dist/primitives/Input/Textarea.stories.svelte +137 -137
- package/dist/primitives/Input/Textarea.svelte +35 -35
- package/dist/primitives/Label/Label.svelte +37 -37
- package/dist/primitives/Modal/Modal.spec.js +95 -95
- package/dist/primitives/Modal/Modal.stories.svelte +86 -86
- package/dist/primitives/Modal/Modal.svelte +158 -158
- package/dist/primitives/NumberInput/NumberInput.svelte +106 -106
- package/dist/primitives/Pagination/Pagination.stories.svelte +76 -76
- package/dist/primitives/Pagination/Pagination.svelte +261 -261
- package/dist/primitives/Radio/Radio.stories.svelte +80 -80
- package/dist/primitives/Radio/Radio.svelte +67 -67
- package/dist/primitives/Skeleton/CardPlaceholder.svelte +87 -87
- package/dist/primitives/Skeleton/ImagePlaceholder.svelte +59 -59
- package/dist/primitives/Skeleton/ListPlaceholder.svelte +76 -76
- package/dist/primitives/Skeleton/Skeleton.stories.svelte +151 -151
- package/dist/primitives/Skeleton/Skeleton.svelte +26 -26
- package/dist/primitives/Spinner/Spinner.spec.js +75 -75
- package/dist/primitives/Spinner/Spinner.stories.svelte +29 -29
- package/dist/primitives/Spinner/Spinner.svelte +20 -20
- package/dist/primitives/Tabs/TabItem.svelte +49 -49
- package/dist/primitives/Tabs/Tabs.stories.svelte +112 -112
- package/dist/primitives/Tabs/Tabs.svelte +123 -123
- package/dist/primitives/Toggle.spec.js +127 -127
- package/dist/primitives/Toggle.stories.svelte +92 -92
- package/dist/primitives/Toggle.svelte +71 -71
- package/dist/primitives/Typography/Typography.svelte +53 -53
- package/dist/primitives/ValidationError.spec.js +103 -103
- package/dist/primitives/ValidationError.stories.svelte +69 -69
- package/dist/primitives/ValidationError.svelte +29 -29
- package/dist/recipes/CropImage/CropImage.spec.js +216 -216
- package/dist/recipes/CropImage/CropImage.stories.svelte +104 -104
- package/dist/recipes/CropImage/CropImage.svelte +238 -238
- package/dist/recipes/ImageUploader/ImageUploader.stories.svelte +125 -125
- package/dist/recipes/ImageUploader/ImageUploader.svelte +804 -804
- package/dist/recipes/SuperLogin/SuperLogin.svelte +7 -6
- package/dist/recipes/SuperLogin/SuperLogin.svelte.d.ts.map +1 -1
- package/dist/recipes/Toaster/Toaster.stories.svelte +62 -62
- package/dist/recipes/feedback/EmptyState/EmptyState.svelte +1 -1
- package/dist/recipes/feedback/ErrorDisplay.spec.js +69 -69
- package/dist/recipes/feedback/ErrorDisplay.stories.svelte +101 -101
- package/dist/recipes/feedback/ErrorDisplay.svelte +1 -1
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.spec.js +129 -129
- package/dist/recipes/feedback/StatusIndicator/StatusIndicator.svelte +157 -157
- package/dist/recipes/fields/CheckboxField.svelte +85 -85
- package/dist/recipes/fields/FormField.svelte +58 -58
- package/dist/recipes/fields/RadioGroup.svelte +95 -95
- package/dist/recipes/fields/SelectField.svelte +80 -80
- package/dist/recipes/fields/TextareaField.svelte +97 -97
- package/dist/recipes/fields/ToggleField.svelte +60 -60
- package/dist/recipes/fields/index.js +7 -7
- package/dist/recipes/inputs/MultiSelect.spec.js +257 -257
- package/dist/recipes/inputs/MultiSelect.stories.svelte +133 -133
- package/dist/recipes/inputs/MultiSelect.svelte +249 -249
- package/dist/recipes/inputs/OTPInput.spec.js +238 -238
- package/dist/recipes/inputs/OTPInput.stories.svelte +162 -162
- package/dist/recipes/inputs/OTPInput.svelte +29 -29
- package/dist/recipes/inputs/PasswordInput.svelte +22 -22
- package/dist/recipes/inputs/PasswordStrengthIndicator/PasswordStrengthIndicator.spec.js +173 -173
- package/dist/recipes/inputs/PasswordStrengthIndicator/PasswordStrengthIndicator.svelte +43 -43
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.spec.js +300 -300
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.stories.svelte +123 -123
- package/dist/recipes/inputs/PlaceAutocomplete/PlaceAutocomplete.svelte +326 -326
- package/dist/recipes/inputs/Search.svelte +37 -37
- package/dist/recipes/inputs/SelectDropdown.svelte +57 -57
- package/dist/recipes/modals/AlertModal.svelte +130 -130
- package/dist/recipes/modals/ConfirmationModal.spec.js +191 -191
- package/dist/recipes/modals/ConfirmationModal.stories.svelte +119 -119
- package/dist/recipes/modals/ConfirmationModal.svelte +152 -152
- package/dist/recipes/modals/InputModal.svelte +182 -182
- package/dist/recipes/modals/ModalStateManager.spec.js +100 -100
- package/dist/recipes/modals/ModalStateManager.svelte +77 -77
- package/dist/recipes/modals/ModalTestWrapper.svelte +65 -65
- package/dist/recipes/modals/StatusModal.svelte +206 -206
- package/dist/services/EventService.js +75 -75
- package/dist/services/EventService.spec.js +217 -217
- package/dist/services/ShowService.spec.js +342 -342
- package/dist/stores/auth.js +36 -36
- package/dist/stores/auth.spec.js +139 -139
- package/dist/stores/toaster.js +13 -13
- package/dist/stories/ButtonAuditReview.stories.svelte +14 -14
- package/dist/stories/ButtonAuditReview.svelte +427 -427
- package/dist/stories/PatternsGallery.stories.svelte +19 -19
- package/dist/stories/PatternsGallery.svelte +206 -206
- package/dist/stories/PrimitivesGallery.stories.svelte +19 -19
- package/dist/stories/PrimitivesGallery.svelte +725 -725
- package/dist/stories/RecipesGallery.stories.svelte +19 -19
- package/dist/stories/RecipesGallery.svelte +271 -271
- package/dist/stories/button-audit-manifest.json +11186 -11186
- package/dist/tailwind/preset.cjs +82 -82
- package/dist/tokens/tokens.css +87 -87
- package/dist/utils/transitions.d.ts +24 -0
- package/dist/utils/transitions.d.ts.map +1 -0
- package/dist/utils/transitions.js +62 -0
- package/dist/utils/utils.js +354 -354
- package/package.json +283 -283
|
@@ -1,211 +1,211 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/svelte';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { expect, describe, test, vi } from 'vitest';
|
|
4
|
-
import Button from './Button.svelte';
|
|
5
|
-
|
|
6
|
-
function setupTest(args = {}) {
|
|
7
|
-
const user = userEvent.setup();
|
|
8
|
-
const onClick = vi.fn();
|
|
9
|
-
const { component } = render(Button, { props: { ...args } });
|
|
10
|
-
component.$on('click', onClick);
|
|
11
|
-
const button = screen.getByRole('button');
|
|
12
|
-
return {
|
|
13
|
-
user,
|
|
14
|
-
component,
|
|
15
|
-
onClick,
|
|
16
|
-
button,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe('Button Component Tests', () => {
|
|
21
|
-
test('Renders Button with default props', () => {
|
|
22
|
-
const { button } = setupTest();
|
|
23
|
-
expect(button).toBeInTheDocument();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('Handles click event', async () => {
|
|
27
|
-
const { user, button, onClick } = setupTest();
|
|
28
|
-
await user.click(button);
|
|
29
|
-
expect(onClick).toHaveBeenCalledOnce();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('Disables button when disabled prop is true', async () => {
|
|
33
|
-
const { button, onClick } = setupTest({ disabled: true });
|
|
34
|
-
expect(button).toBeDisabled();
|
|
35
|
-
await userEvent.click(button);
|
|
36
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('Renders with before and after icons', () => {
|
|
40
|
-
const { button } = setupTest({ beforeIcon: 'icon-before.png', afterIcon: 'icon-after.png' });
|
|
41
|
-
|
|
42
|
-
const beforeIcon = button.querySelector('img.mr-2');
|
|
43
|
-
const afterIcon = button.querySelector('img.ml-2');
|
|
44
|
-
|
|
45
|
-
expect(beforeIcon).toBeInTheDocument();
|
|
46
|
-
expect(beforeIcon).toHaveAttribute('src', 'icon-before.png');
|
|
47
|
-
|
|
48
|
-
expect(afterIcon).toBeInTheDocument();
|
|
49
|
-
expect(afterIcon).toHaveAttribute('src', 'icon-after.png');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('Handles custom classes passed via className prop', () => {
|
|
53
|
-
const { button } = setupTest({ className: 'custom-class' });
|
|
54
|
-
expect(button).toHaveClass('custom-class');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('Button Variants', () => {
|
|
59
|
-
test('Default variant is blue-solid', () => {
|
|
60
|
-
const { button } = setupTest();
|
|
61
|
-
expect(button).toHaveClass('btn-blue-solid');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('Blue outline variant', () => {
|
|
65
|
-
const { button } = setupTest({ variant: 'blue-outline' });
|
|
66
|
-
expect(button).toHaveClass('btn-blue-outline');
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('Gray outline variant', () => {
|
|
70
|
-
const { button } = setupTest({ variant: 'gray-outline' });
|
|
71
|
-
expect(button).toHaveClass('btn-gray-outline');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('Red solid variant', () => {
|
|
75
|
-
const { button } = setupTest({ variant: 'red-solid' });
|
|
76
|
-
expect(button).toHaveClass('btn-red-solid');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('Red outline variant', () => {
|
|
80
|
-
const { button } = setupTest({ variant: 'red-outline' });
|
|
81
|
-
expect(button).toHaveClass('btn-red-outline');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('Red text variant', () => {
|
|
85
|
-
const { button } = setupTest({ variant: 'red-text' });
|
|
86
|
-
expect(button).toHaveClass('btn-red-text');
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('Gray text variant', () => {
|
|
90
|
-
const { button } = setupTest({ variant: 'gray-text' });
|
|
91
|
-
expect(button).toHaveClass('btn-gray-text');
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('Button Sizes', () => {
|
|
96
|
-
test('Full width size', () => {
|
|
97
|
-
const { button } = setupTest({ size: 'full' });
|
|
98
|
-
expect(button).toHaveClass('w-full');
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('Full width on mobile, auto on desktop', () => {
|
|
102
|
-
const { button } = setupTest({ size: 'full-md-auto' });
|
|
103
|
-
expect(button).toHaveClass('w-full');
|
|
104
|
-
expect(button).toHaveClass('md:w-auto');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
test('Large size', () => {
|
|
108
|
-
const { button } = setupTest({ size: 'lg' });
|
|
109
|
-
expect(button).toHaveClass('px-6');
|
|
110
|
-
expect(button).toHaveClass('py-3');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('Medium size', () => {
|
|
114
|
-
const { button } = setupTest({ size: 'md' });
|
|
115
|
-
expect(button).toHaveClass('px-3');
|
|
116
|
-
expect(button).toHaveClass('py-3');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('Small size', () => {
|
|
120
|
-
const { button } = setupTest({ size: 'sm' });
|
|
121
|
-
expect(button).toHaveClass('text-xs');
|
|
122
|
-
expect(button).toHaveClass('rounded-md');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
test('Extra small size', () => {
|
|
126
|
-
const { button } = setupTest({ size: 'xs' });
|
|
127
|
-
expect(button).toHaveClass('text-xs');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test('Nav size', () => {
|
|
131
|
-
const { button } = setupTest({ size: 'nav' });
|
|
132
|
-
expect(button).toHaveClass('w-full');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('Half width size', () => {
|
|
136
|
-
const { button } = setupTest({ size: 'half' });
|
|
137
|
-
expect(button.className).toMatch(/w-\[48%\]/);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe('Button Min Width', () => {
|
|
142
|
-
test('Small min width', () => {
|
|
143
|
-
const { button } = setupTest({ minWidth: 'sm' });
|
|
144
|
-
expect(button.className).toMatch(/min-w-\[100px\]/);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('Action min width', () => {
|
|
148
|
-
const { button } = setupTest({ minWidth: 'action' });
|
|
149
|
-
expect(button.className).toMatch(/min-w-\[150px\]/);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('Modal min width', () => {
|
|
153
|
-
const { button } = setupTest({ minWidth: 'modal' });
|
|
154
|
-
expect(button.className).toMatch(/min-w-\[130px\]/);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
describe('Button States', () => {
|
|
159
|
-
test('Loading state disables button', async () => {
|
|
160
|
-
const { button, onClick } = setupTest({ loading: true });
|
|
161
|
-
|
|
162
|
-
expect(button).toBeDisabled();
|
|
163
|
-
await userEvent.click(button);
|
|
164
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('Success state shows checkmark and disables button', async () => {
|
|
168
|
-
const { button, onClick } = setupTest({ success: true });
|
|
169
|
-
|
|
170
|
-
expect(button).toBeDisabled();
|
|
171
|
-
expect(button).toHaveClass('btn-success');
|
|
172
|
-
await userEvent.click(button);
|
|
173
|
-
expect(onClick).not.toHaveBeenCalled();
|
|
174
|
-
|
|
175
|
-
// Should have checkmark SVG
|
|
176
|
-
expect(button.querySelector('svg')).toBeInTheDocument();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test('Active state for nav items', () => {
|
|
180
|
-
const { button } = setupTest({ active: true, size: 'nav' });
|
|
181
|
-
expect(button).toHaveClass('btn-active');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test('Responsive class adds microinteraction', () => {
|
|
185
|
-
const { button } = setupTest({ responsive: true });
|
|
186
|
-
expect(button).toHaveClass('btn-responsive');
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('Button as Link', () => {
|
|
191
|
-
test('Renders as anchor when href is provided', () => {
|
|
192
|
-
render(Button, { props: { href: '/test-link' } });
|
|
193
|
-
const link = screen.getByRole('link');
|
|
194
|
-
expect(link).toBeInTheDocument();
|
|
195
|
-
expect(link).toHaveAttribute('href', '/test-link');
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('Does not render as anchor when href is not provided', () => {
|
|
199
|
-
setupTest();
|
|
200
|
-
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
201
|
-
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('Button Justify', () => {
|
|
206
|
-
test('Between justify for list-item style', () => {
|
|
207
|
-
const { button } = setupTest({ justify: 'between' });
|
|
208
|
-
// justify-between class is prefixed with ! to override default
|
|
209
|
-
expect(button.className).toMatch(/justify-between/);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
1
|
+
import { render, screen } from '@testing-library/svelte';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { expect, describe, test, vi } from 'vitest';
|
|
4
|
+
import Button from './Button.svelte';
|
|
5
|
+
|
|
6
|
+
function setupTest(args = {}) {
|
|
7
|
+
const user = userEvent.setup();
|
|
8
|
+
const onClick = vi.fn();
|
|
9
|
+
const { component } = render(Button, { props: { ...args } });
|
|
10
|
+
component.$on('click', onClick);
|
|
11
|
+
const button = screen.getByRole('button');
|
|
12
|
+
return {
|
|
13
|
+
user,
|
|
14
|
+
component,
|
|
15
|
+
onClick,
|
|
16
|
+
button,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('Button Component Tests', () => {
|
|
21
|
+
test('Renders Button with default props', () => {
|
|
22
|
+
const { button } = setupTest();
|
|
23
|
+
expect(button).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Handles click event', async () => {
|
|
27
|
+
const { user, button, onClick } = setupTest();
|
|
28
|
+
await user.click(button);
|
|
29
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('Disables button when disabled prop is true', async () => {
|
|
33
|
+
const { button, onClick } = setupTest({ disabled: true });
|
|
34
|
+
expect(button).toBeDisabled();
|
|
35
|
+
await userEvent.click(button);
|
|
36
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('Renders with before and after icons', () => {
|
|
40
|
+
const { button } = setupTest({ beforeIcon: 'icon-before.png', afterIcon: 'icon-after.png' });
|
|
41
|
+
|
|
42
|
+
const beforeIcon = button.querySelector('img.mr-2');
|
|
43
|
+
const afterIcon = button.querySelector('img.ml-2');
|
|
44
|
+
|
|
45
|
+
expect(beforeIcon).toBeInTheDocument();
|
|
46
|
+
expect(beforeIcon).toHaveAttribute('src', 'icon-before.png');
|
|
47
|
+
|
|
48
|
+
expect(afterIcon).toBeInTheDocument();
|
|
49
|
+
expect(afterIcon).toHaveAttribute('src', 'icon-after.png');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Handles custom classes passed via className prop', () => {
|
|
53
|
+
const { button } = setupTest({ className: 'custom-class' });
|
|
54
|
+
expect(button).toHaveClass('custom-class');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('Button Variants', () => {
|
|
59
|
+
test('Default variant is blue-solid', () => {
|
|
60
|
+
const { button } = setupTest();
|
|
61
|
+
expect(button).toHaveClass('btn-blue-solid');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('Blue outline variant', () => {
|
|
65
|
+
const { button } = setupTest({ variant: 'blue-outline' });
|
|
66
|
+
expect(button).toHaveClass('btn-blue-outline');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('Gray outline variant', () => {
|
|
70
|
+
const { button } = setupTest({ variant: 'gray-outline' });
|
|
71
|
+
expect(button).toHaveClass('btn-gray-outline');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Red solid variant', () => {
|
|
75
|
+
const { button } = setupTest({ variant: 'red-solid' });
|
|
76
|
+
expect(button).toHaveClass('btn-red-solid');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('Red outline variant', () => {
|
|
80
|
+
const { button } = setupTest({ variant: 'red-outline' });
|
|
81
|
+
expect(button).toHaveClass('btn-red-outline');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('Red text variant', () => {
|
|
85
|
+
const { button } = setupTest({ variant: 'red-text' });
|
|
86
|
+
expect(button).toHaveClass('btn-red-text');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('Gray text variant', () => {
|
|
90
|
+
const { button } = setupTest({ variant: 'gray-text' });
|
|
91
|
+
expect(button).toHaveClass('btn-gray-text');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('Button Sizes', () => {
|
|
96
|
+
test('Full width size', () => {
|
|
97
|
+
const { button } = setupTest({ size: 'full' });
|
|
98
|
+
expect(button).toHaveClass('w-full');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('Full width on mobile, auto on desktop', () => {
|
|
102
|
+
const { button } = setupTest({ size: 'full-md-auto' });
|
|
103
|
+
expect(button).toHaveClass('w-full');
|
|
104
|
+
expect(button).toHaveClass('md:w-auto');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('Large size', () => {
|
|
108
|
+
const { button } = setupTest({ size: 'lg' });
|
|
109
|
+
expect(button).toHaveClass('px-6');
|
|
110
|
+
expect(button).toHaveClass('py-3');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('Medium size', () => {
|
|
114
|
+
const { button } = setupTest({ size: 'md' });
|
|
115
|
+
expect(button).toHaveClass('px-3');
|
|
116
|
+
expect(button).toHaveClass('py-3');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('Small size', () => {
|
|
120
|
+
const { button } = setupTest({ size: 'sm' });
|
|
121
|
+
expect(button).toHaveClass('text-xs');
|
|
122
|
+
expect(button).toHaveClass('rounded-md');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('Extra small size', () => {
|
|
126
|
+
const { button } = setupTest({ size: 'xs' });
|
|
127
|
+
expect(button).toHaveClass('text-xs');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('Nav size', () => {
|
|
131
|
+
const { button } = setupTest({ size: 'nav' });
|
|
132
|
+
expect(button).toHaveClass('w-full');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('Half width size', () => {
|
|
136
|
+
const { button } = setupTest({ size: 'half' });
|
|
137
|
+
expect(button.className).toMatch(/w-\[48%\]/);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('Button Min Width', () => {
|
|
142
|
+
test('Small min width', () => {
|
|
143
|
+
const { button } = setupTest({ minWidth: 'sm' });
|
|
144
|
+
expect(button.className).toMatch(/min-w-\[100px\]/);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('Action min width', () => {
|
|
148
|
+
const { button } = setupTest({ minWidth: 'action' });
|
|
149
|
+
expect(button.className).toMatch(/min-w-\[150px\]/);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('Modal min width', () => {
|
|
153
|
+
const { button } = setupTest({ minWidth: 'modal' });
|
|
154
|
+
expect(button.className).toMatch(/min-w-\[130px\]/);
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe('Button States', () => {
|
|
159
|
+
test('Loading state disables button', async () => {
|
|
160
|
+
const { button, onClick } = setupTest({ loading: true });
|
|
161
|
+
|
|
162
|
+
expect(button).toBeDisabled();
|
|
163
|
+
await userEvent.click(button);
|
|
164
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('Success state shows checkmark and disables button', async () => {
|
|
168
|
+
const { button, onClick } = setupTest({ success: true });
|
|
169
|
+
|
|
170
|
+
expect(button).toBeDisabled();
|
|
171
|
+
expect(button).toHaveClass('btn-success');
|
|
172
|
+
await userEvent.click(button);
|
|
173
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
174
|
+
|
|
175
|
+
// Should have checkmark SVG
|
|
176
|
+
expect(button.querySelector('svg')).toBeInTheDocument();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('Active state for nav items', () => {
|
|
180
|
+
const { button } = setupTest({ active: true, size: 'nav' });
|
|
181
|
+
expect(button).toHaveClass('btn-active');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('Responsive class adds microinteraction', () => {
|
|
185
|
+
const { button } = setupTest({ responsive: true });
|
|
186
|
+
expect(button).toHaveClass('btn-responsive');
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('Button as Link', () => {
|
|
191
|
+
test('Renders as anchor when href is provided', () => {
|
|
192
|
+
render(Button, { props: { href: '/test-link' } });
|
|
193
|
+
const link = screen.getByRole('link');
|
|
194
|
+
expect(link).toBeInTheDocument();
|
|
195
|
+
expect(link).toHaveAttribute('href', '/test-link');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('Does not render as anchor when href is not provided', () => {
|
|
199
|
+
setupTest();
|
|
200
|
+
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
201
|
+
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('Button Justify', () => {
|
|
206
|
+
test('Between justify for list-item style', () => {
|
|
207
|
+
const { button } = setupTest({ justify: 'between' });
|
|
208
|
+
// justify-between class is prefixed with ! to override default
|
|
209
|
+
expect(button.className).toMatch(/justify-between/);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
<script module>
|
|
2
|
-
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
|
-
import Button from "./Button.svelte";
|
|
4
|
-
import ButtonSaveDemo from "./ButtonSaveDemo.svelte";
|
|
5
|
-
import ButtonVariantShowcase from "./ButtonVariantShowcase.svelte";
|
|
6
|
-
|
|
7
|
-
import Add from "./../../assets/svg/add-main.svg";
|
|
8
|
-
import ArrowLeft from "./../../assets/svg/arrow-left-02.svg";
|
|
9
|
-
import DeleteIcon from "./../../assets/svg/delete-02.svg";
|
|
10
|
-
|
|
11
|
-
const { Story } = defineMeta({
|
|
12
|
-
title: "Components/Button",
|
|
13
|
-
component: Button,
|
|
14
|
-
tags: ['autodocs'],
|
|
15
|
-
argTypes: {
|
|
16
|
-
variant: {
|
|
17
|
-
control: "select",
|
|
18
|
-
options: ["default", "alternative", "outline", "red", "red-outline", "ghost", "ghost-red", "link", "toggle", "icon"],
|
|
19
|
-
},
|
|
20
|
-
size: {
|
|
21
|
-
control: "select",
|
|
22
|
-
options: ["xs", "sm", "md", "lg", "xl", "xl-medium", "full", "full-md-auto", "half"],
|
|
23
|
-
},
|
|
24
|
-
disabled: { control: "boolean" },
|
|
25
|
-
loading: { control: "boolean" },
|
|
26
|
-
success: { control: "boolean" },
|
|
27
|
-
successText: { control: "text" },
|
|
28
|
-
active: { control: "boolean" },
|
|
29
|
-
},
|
|
30
|
-
args: {
|
|
31
|
-
children: "Button",
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
</script>
|
|
35
|
-
|
|
36
|
-
<!-- Full Showcase (uses dedicated component) -->
|
|
37
|
-
<Story name="All Variants Showcase">
|
|
38
|
-
{#snippet template()}
|
|
39
|
-
<ButtonVariantShowcase />
|
|
40
|
-
{/snippet}
|
|
41
|
-
</Story>
|
|
42
|
-
|
|
43
|
-
<!-- Interactive Playground -->
|
|
44
|
-
<Story name="Playground" args={{ children: "Click me" }} />
|
|
45
|
-
|
|
46
|
-
<!-- ========== VARIANTS ========== -->
|
|
47
|
-
<Story name="default" args={{ variant: "default", children: "Primary Button" }} />
|
|
48
|
-
<Story name="alternative" args={{ variant: "alternative", children: "Secondary" }} />
|
|
49
|
-
<Story name="outline" args={{ variant: "outline", children: "Outline" }} />
|
|
50
|
-
<Story name="ghost" args={{ variant: "ghost", children: "Ghost" }} />
|
|
51
|
-
<Story name="link" args={{ variant: "link", children: "Link style" }} />
|
|
52
|
-
<Story name="red" args={{ variant: "red", children: "Delete" }} />
|
|
53
|
-
<Story name="red-outline" args={{ variant: "red-outline", children: "Remove" }} />
|
|
54
|
-
<Story name="ghost-red" args={{ variant: "ghost-red", children: "Sign out" }} />
|
|
55
|
-
<Story name="toggle" args={{ variant: "toggle", children: "Filter" }} />
|
|
56
|
-
<Story name="toggle (active)" args={{ variant: "toggle", active: true, children: "Selected" }} />
|
|
57
|
-
|
|
58
|
-
<!-- ========== SIZES ========== -->
|
|
59
|
-
<Story name="Size: xs" args={{ size: "xs", children: "Extra Small" }} />
|
|
60
|
-
<Story name="Size: sm" args={{ size: "sm", children: "Small" }} />
|
|
61
|
-
<Story name="Size: md" args={{ size: "md", children: "Medium" }} />
|
|
62
|
-
<Story name="Size: lg" args={{ size: "lg", children: "Large" }} />
|
|
63
|
-
<Story name="Size: xl" args={{ size: "xl", children: "Extra Large" }} />
|
|
64
|
-
<Story name="Size: full" args={{ size: "full", children: "Full Width" }} />
|
|
65
|
-
<Story name="Size: xl-medium" args={{ size: "xl-medium", children: "Login Button" }} />
|
|
66
|
-
<Story name="Size: half" args={{ size: "half", children: "Half Width" }} />
|
|
67
|
-
|
|
68
|
-
<!-- ========== STATES ========== -->
|
|
69
|
-
<Story name="Disabled" args={{ disabled: true, children: "Disabled" }} />
|
|
70
|
-
<Story name="Loading" args={{ loading: true, children: "Saving..." }} />
|
|
71
|
-
<Story name="Success" args={{ success: true, successText: "Saved!", children: "Save" }} />
|
|
72
|
-
|
|
73
|
-
<!-- ========== INTERACTIVE DEMO ========== -->
|
|
74
|
-
<Story name="Save Flow Demo" asChild>
|
|
75
|
-
<ButtonSaveDemo />
|
|
76
|
-
</Story>
|
|
1
|
+
<script module>
|
|
2
|
+
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import Button from "./Button.svelte";
|
|
4
|
+
import ButtonSaveDemo from "./ButtonSaveDemo.svelte";
|
|
5
|
+
import ButtonVariantShowcase from "./ButtonVariantShowcase.svelte";
|
|
6
|
+
|
|
7
|
+
import Add from "./../../assets/svg/add-main.svg";
|
|
8
|
+
import ArrowLeft from "./../../assets/svg/arrow-left-02.svg";
|
|
9
|
+
import DeleteIcon from "./../../assets/svg/delete-02.svg";
|
|
10
|
+
|
|
11
|
+
const { Story } = defineMeta({
|
|
12
|
+
title: "Components/Button",
|
|
13
|
+
component: Button,
|
|
14
|
+
tags: ['autodocs'],
|
|
15
|
+
argTypes: {
|
|
16
|
+
variant: {
|
|
17
|
+
control: "select",
|
|
18
|
+
options: ["default", "alternative", "outline", "red", "red-outline", "ghost", "ghost-red", "link", "toggle", "icon"],
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
control: "select",
|
|
22
|
+
options: ["xs", "sm", "md", "lg", "xl", "xl-medium", "full", "full-md-auto", "half"],
|
|
23
|
+
},
|
|
24
|
+
disabled: { control: "boolean" },
|
|
25
|
+
loading: { control: "boolean" },
|
|
26
|
+
success: { control: "boolean" },
|
|
27
|
+
successText: { control: "text" },
|
|
28
|
+
active: { control: "boolean" },
|
|
29
|
+
},
|
|
30
|
+
args: {
|
|
31
|
+
children: "Button",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<!-- Full Showcase (uses dedicated component) -->
|
|
37
|
+
<Story name="All Variants Showcase">
|
|
38
|
+
{#snippet template()}
|
|
39
|
+
<ButtonVariantShowcase />
|
|
40
|
+
{/snippet}
|
|
41
|
+
</Story>
|
|
42
|
+
|
|
43
|
+
<!-- Interactive Playground -->
|
|
44
|
+
<Story name="Playground" args={{ children: "Click me" }} />
|
|
45
|
+
|
|
46
|
+
<!-- ========== VARIANTS ========== -->
|
|
47
|
+
<Story name="default" args={{ variant: "default", children: "Primary Button" }} />
|
|
48
|
+
<Story name="alternative" args={{ variant: "alternative", children: "Secondary" }} />
|
|
49
|
+
<Story name="outline" args={{ variant: "outline", children: "Outline" }} />
|
|
50
|
+
<Story name="ghost" args={{ variant: "ghost", children: "Ghost" }} />
|
|
51
|
+
<Story name="link" args={{ variant: "link", children: "Link style" }} />
|
|
52
|
+
<Story name="red" args={{ variant: "red", children: "Delete" }} />
|
|
53
|
+
<Story name="red-outline" args={{ variant: "red-outline", children: "Remove" }} />
|
|
54
|
+
<Story name="ghost-red" args={{ variant: "ghost-red", children: "Sign out" }} />
|
|
55
|
+
<Story name="toggle" args={{ variant: "toggle", children: "Filter" }} />
|
|
56
|
+
<Story name="toggle (active)" args={{ variant: "toggle", active: true, children: "Selected" }} />
|
|
57
|
+
|
|
58
|
+
<!-- ========== SIZES ========== -->
|
|
59
|
+
<Story name="Size: xs" args={{ size: "xs", children: "Extra Small" }} />
|
|
60
|
+
<Story name="Size: sm" args={{ size: "sm", children: "Small" }} />
|
|
61
|
+
<Story name="Size: md" args={{ size: "md", children: "Medium" }} />
|
|
62
|
+
<Story name="Size: lg" args={{ size: "lg", children: "Large" }} />
|
|
63
|
+
<Story name="Size: xl" args={{ size: "xl", children: "Extra Large" }} />
|
|
64
|
+
<Story name="Size: full" args={{ size: "full", children: "Full Width" }} />
|
|
65
|
+
<Story name="Size: xl-medium" args={{ size: "xl-medium", children: "Login Button" }} />
|
|
66
|
+
<Story name="Size: half" args={{ size: "half", children: "Half Width" }} />
|
|
67
|
+
|
|
68
|
+
<!-- ========== STATES ========== -->
|
|
69
|
+
<Story name="Disabled" args={{ disabled: true, children: "Disabled" }} />
|
|
70
|
+
<Story name="Loading" args={{ loading: true, children: "Saving..." }} />
|
|
71
|
+
<Story name="Success" args={{ success: true, successText: "Saved!", children: "Save" }} />
|
|
72
|
+
|
|
73
|
+
<!-- ========== INTERACTIVE DEMO ========== -->
|
|
74
|
+
<Story name="Save Flow Demo" asChild>
|
|
75
|
+
<ButtonSaveDemo />
|
|
76
|
+
</Story>
|