Skip to content

Commit 0a5071d

Browse files
committed
add more tests
# Conflicts: # package-lock.json
1 parent b804c0b commit 0a5071d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+16773
-10759
lines changed

.codacy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
engines:
2+
eslint:
3+
enabled: true
4+
prettier:
5+
enabled: true
6+
exclude_paths:
7+
- "**/*.md"

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

.storybook/stories/Select.stories.js

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Select } from '../../src';
33
import { optionsBase } from '../../docs/src/options';
44

55
const options = optionsBase(4);
6+
const largeOptions = optionsBase(20000);
7+
68
const baseArgs = {
79
...Select.defaultProps,
810
options,
@@ -22,5 +24,231 @@ export default {
2224
}
2325
};
2426

27+
// Basic single select
2528
export const Basic = { args: baseArgs };
29+
30+
// Multi select
2631
export const Multi = { args: { ...baseArgs, multi: true } };
32+
33+
// Form with validation
34+
export const FormValidation = {
35+
args: {
36+
...baseArgs,
37+
required: true,
38+
name: 'select-field',
39+
pattern: '.+'
40+
}
41+
};
42+
43+
// Windowed (Large Dataset)
44+
export const WindowedLargeDataset = {
45+
args: {
46+
...baseArgs,
47+
options: largeOptions,
48+
dropdownRenderer: ({ props, state, methods }) => (
49+
<div style={{ maxHeight: '300px', overflow: 'auto' }}>
50+
{state.searchResults.map((item, index) => (
51+
<div
52+
key={index}
53+
onClick={() => methods.addItem(item)}
54+
style={{ padding: '10px', cursor: 'pointer' }}>
55+
{item.label}
56+
</div>
57+
))}
58+
</div>
59+
)
60+
}
61+
};
62+
63+
// Select All functionality
64+
export const SelectAllExample = {
65+
args: {
66+
...baseArgs,
67+
multi: true,
68+
selectAll: true,
69+
selectAllLabel: 'Select all',
70+
clearAllLabel: 'Clear all'
71+
}
72+
};
73+
74+
// Custom Item Renderer
75+
export const CustomItemRenderer = {
76+
args: {
77+
...baseArgs,
78+
itemRenderer: ({ item, itemIndex, props, state, methods }) => (
79+
<div
80+
key={itemIndex}
81+
onClick={() => methods.addItem(item)}
82+
style={{
83+
padding: '10px',
84+
cursor: 'pointer',
85+
backgroundColor: methods.isSelected(item) ? '#f2f2f2' : 'white'
86+
}}>
87+
<div style={{ fontWeight: 'bold' }}>{item.label}</div>
88+
<div style={{ fontSize: '12px', color: '#666' }}>{item.value}</div>
89+
</div>
90+
)
91+
}
92+
};
93+
94+
// Custom Content and Dropdown
95+
export const CustomContentAndDropdown = {
96+
args: {
97+
...baseArgs,
98+
contentRenderer: ({ props, state, methods }) => (
99+
<div style={{ padding: '10px' }}>
100+
{state.values.length ? state.values.map((item) => item.label).join(', ') : 'Select...'}
101+
</div>
102+
),
103+
dropdownRenderer: ({ props, state, methods }) => (
104+
<div style={{ padding: '10px', border: '1px solid #ccc' }}>
105+
{state.searchResults.map((item, index) => (
106+
<div
107+
key={index}
108+
onClick={() => methods.addItem(item)}
109+
style={{ padding: '5px', cursor: 'pointer' }}>
110+
{item.label}
111+
</div>
112+
))}
113+
</div>
114+
)
115+
}
116+
};
117+
118+
// Custom Dropdown Handle
119+
export const CustomDropdownHandle = {
120+
args: {
121+
...baseArgs,
122+
dropdownHandleRenderer: ({ state }) => (
123+
<span style={{ padding: '5px' }}>{state.dropdown ? '▲' : '▼'}</span>
124+
)
125+
}
126+
};
127+
128+
// With Animation
129+
export const WithAnimation = {
130+
args: {
131+
...baseArgs,
132+
style: {
133+
transition: 'all 0.2s ease'
134+
},
135+
contentRenderer: ({ props, state, methods }) => (
136+
<div
137+
style={{
138+
transition: 'all 0.2s ease',
139+
transform: state.dropdown ? 'scale(1.05)' : 'scale(1)'
140+
}}>
141+
{state.values.length ? state.values.map((item) => item.label).join(', ') : 'Select...'}
142+
</div>
143+
)
144+
}
145+
};
146+
147+
// Custom Search Function
148+
export const CustomSearch = {
149+
args: {
150+
...baseArgs,
151+
searchFn: ({ state, props }) => {
152+
const regexp = new RegExp(state.search, 'i');
153+
return props.options.filter((item) => regexp.test(item.label) || regexp.test(item.value));
154+
}
155+
}
156+
};
157+
158+
// No Data Example
159+
export const NoDataExample = {
160+
args: {
161+
...baseArgs,
162+
options: [],
163+
noDataLabel: 'No options available',
164+
noDataRenderer: ({ props, state, methods }) => (
165+
<div style={{ padding: '10px', color: '#666' }}>{props.noDataLabel}</div>
166+
)
167+
}
168+
};
169+
170+
// Searchable select
171+
export const Searchable = {
172+
args: {
173+
...baseArgs,
174+
searchable: true,
175+
placeholder: 'Search and select...'
176+
}
177+
};
178+
179+
// Disabled select
180+
export const Disabled = {
181+
args: {
182+
...baseArgs,
183+
disabled: true,
184+
values: [options[0]]
185+
}
186+
};
187+
188+
// Select with custom colors
189+
export const CustomColor = {
190+
args: {
191+
...baseArgs,
192+
color: '#ff0000'
193+
}
194+
};
195+
196+
// Select with create option
197+
export const CreateOption = {
198+
args: {
199+
...baseArgs,
200+
create: true,
201+
createNewLabel: 'Create: {search}'
202+
}
203+
};
204+
205+
// Select with loading state
206+
export const Loading = {
207+
args: {
208+
...baseArgs,
209+
loading: true
210+
}
211+
};
212+
213+
// Select with clear option
214+
export const Clearable = {
215+
args: {
216+
...baseArgs,
217+
clearable: true,
218+
values: [options[0]]
219+
}
220+
};
221+
222+
// Select with custom dropdown position
223+
export const DropdownPosition = {
224+
args: {
225+
...baseArgs,
226+
dropdownPosition: 'top'
227+
}
228+
};
229+
230+
// Select with RTL support
231+
export const RTLSupport = {
232+
args: {
233+
...baseArgs,
234+
direction: 'rtl'
235+
}
236+
};
237+
238+
// Select with all features
239+
export const AllFeatures = {
240+
args: {
241+
...baseArgs,
242+
multi: true,
243+
searchable: true,
244+
clearable: true,
245+
create: true,
246+
selectAll: true,
247+
dropdownHandle: true,
248+
separator: true,
249+
keepSelectedInList: true,
250+
closeOnSelect: false,
251+
dropdownPosition: 'auto',
252+
values: [options[0]]
253+
}
254+
};

0 commit comments

Comments
 (0)