dropdowns-js 1.1.1 → 1.1.2
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/README.md +0 -126
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,132 +243,6 @@ export default function MyComponent4() {
|
|
|
243
243
|
);
|
|
244
244
|
}
|
|
245
245
|
```
|
|
246
|
-
## 8. Multiple dropdown usage example
|
|
247
|
-
```
|
|
248
|
-
export default function MyComponent5() {
|
|
249
|
-
const [output, setOutput] = useState();
|
|
250
|
-
/* A dropdown whose collection data gets updated, must be given a key attribute, so as to update
|
|
251
|
-
it (key) to cause re-render upon the update of collection data. */
|
|
252
|
-
const [dropdownKey2, setDropdownKey2] = useState(0);
|
|
253
|
-
const keyStep = .000001;
|
|
254
|
-
|
|
255
|
-
const {
|
|
256
|
-
addCollection,
|
|
257
|
-
collectionExists,
|
|
258
|
-
updateCollection,
|
|
259
|
-
getSelected
|
|
260
|
-
} = useCollectionsContext();
|
|
261
|
-
|
|
262
|
-
const drivers = [
|
|
263
|
-
{ fullName: "Thabo Mokoena", licenceCode: "B", id: "771217" },
|
|
264
|
-
{ fullName: "Naledi Khumalo", licenceCode: "EB", id: "850412" },
|
|
265
|
-
{ fullName: "Sipho Dlamini", licenceCode: "C1", id: "861802" },
|
|
266
|
-
{ fullName: "Ayesha Patel", licenceCode: "B", id: "500101" },
|
|
267
|
-
{ fullName: "Johan van der Merwe", licenceCode: "EC", id: "620401" },
|
|
268
|
-
{ fullName: "Lerato Molefe", licenceCode: "A", id: "901012" },
|
|
269
|
-
{ fullName: "Sibusiso Nkosi", licenceCode: "EC1", id: "910512" },
|
|
270
|
-
{ fullName: "Michelle Adams", licenceCode: "B", id: "901012" },
|
|
271
|
-
{ fullName: "Kagiso Tshepe", licenceCode: "C", id: "920115" },
|
|
272
|
-
{ fullName: "Pieter Botha", licenceCode: "A1", id: "960401" },
|
|
273
|
-
{ fullName: "Nomvula Zungu", licenceCode: "B", id: "0792346789" },
|
|
274
|
-
{ fullName: "Riaan Pretorius", licenceCode: "EB", id: "0824567812" },
|
|
275
|
-
{ fullName: "Mandla Sithole", licenceCode: "C1", id: "0735678910" },
|
|
276
|
-
{ fullName: "Fatima Khan", licenceCode: "B", id: "0846789123" },
|
|
277
|
-
{ fullName: "Tshepo Madiba", licenceCode: "EC1", id: "0817890234" },
|
|
278
|
-
{ fullName: "Andre Nel", licenceCode: "A", id: "0728901345" },
|
|
279
|
-
{ fullName: "Zanele Mthembu", licenceCode: "B", id: "0769012456" },
|
|
280
|
-
{ fullName: "Imran Desai", licenceCode: "C", id: "0740123567" },
|
|
281
|
-
{ fullName: "Charlene Jacobs", licenceCode: "EB", id: "0831234678" },
|
|
282
|
-
{ fullName: "Vusi Hlongwane", licenceCode: "EC", id: "0712345789" }
|
|
283
|
-
];
|
|
284
|
-
|
|
285
|
-
useEffect(()=> {
|
|
286
|
-
if (!collectionExists("DRIVING_CODES")) {
|
|
287
|
-
const drivingCodes = [
|
|
288
|
-
"A", "A1", "EC", "EC1", "C", "C1", "B", "EB"
|
|
289
|
-
];
|
|
290
|
-
// Create DRIVING_CODES collection sorted in ascending order.
|
|
291
|
-
addCollection("DRIVING_CODES", // collection name
|
|
292
|
-
drivingCodes, // collection data
|
|
293
|
-
1, // maximum number of selections
|
|
294
|
-
true, // primitive type data
|
|
295
|
-
'asc'); // asc - sort order
|
|
296
|
-
}
|
|
297
|
-
if (!collectionExists("DRIVERS")) {
|
|
298
|
-
// Create a drivers collection sorted in ascending order. Initially empty pending the selection of a driving code.
|
|
299
|
-
|
|
300
|
-
addCollection("DRIVERS",
|
|
301
|
-
[], // empty
|
|
302
|
-
5, // allow max 5 selections
|
|
303
|
-
false, // object type data.
|
|
304
|
-
'fullName asc');
|
|
305
|
-
}
|
|
306
|
-
}, []);
|
|
307
|
-
|
|
308
|
-
/**Respond when the user has chosen a driving licence code */
|
|
309
|
-
function drivingCodeSelected() {
|
|
310
|
-
// Obtain the selected driving codes.
|
|
311
|
-
const selectedDrivingCodes = getSelected("DRIVING_CODES");
|
|
312
|
-
|
|
313
|
-
// Create a string array of driving codes.
|
|
314
|
-
const strSelectedCodes = selectedDrivingCodes; // Expecting a size 1 array
|
|
315
|
-
const selectedCode = strSelectedCodes[0];
|
|
316
|
-
|
|
317
|
-
/*=========Update collection according to selected driving licence code=====*/
|
|
318
|
-
const updateData = drivers.filter(driver=> {
|
|
319
|
-
return selectedCode === driver.licenceCode;
|
|
320
|
-
});
|
|
321
|
-
updateCollection("DRIVERS", updateData);
|
|
322
|
-
/*============================================================================*/
|
|
323
|
-
|
|
324
|
-
// Force the re-render the drivers MultiselectionDropdownObj, since its data has been updated.
|
|
325
|
-
setDropdownKey2(dropdownKey2 + keyStep);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function driversSelected() {
|
|
329
|
-
const selectedDrivers = [...getSelected(collectionNames.DRIVERS)].map(driver => driver.fullName); // Array
|
|
330
|
-
setOutput(selectedDrivers.join(', ')); // List of selected drivers' names.
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
return (
|
|
334
|
-
<div className='container' style={{padding: '5px', backgroundColor: 'green'}}>
|
|
335
|
-
<h1>MultiSelectionDropdownObj Example</h1>
|
|
336
|
-
<p>Select an interest, and then your topic</p>
|
|
337
|
-
<div style={{padding: '2px', display: 'flex'}}>
|
|
338
|
-
<label style={{width: '100px'}}>Lic. Codes</label>
|
|
339
|
-
<MultiSelectionDropdownObj label='Driving Licence Codes'
|
|
340
|
-
collectionName={collectionNames.DRIVING_CODES}
|
|
341
|
-
valueName='code'
|
|
342
|
-
displayName='description'
|
|
343
|
-
onItemsSelected={drivingCodeSelected}
|
|
344
|
-
isDisabled={false}
|
|
345
|
-
dropdownStyle={{color: '#000', backgroundColor: '#66ff66'}}
|
|
346
|
-
buttonStyle={{color: '#fff', backgroundColor: '#008000'}} />
|
|
347
|
-
</div>
|
|
348
|
-
|
|
349
|
-
<div style={{padding: '2px', display: 'flex'}}>
|
|
350
|
-
<label style={{width: '100px'}}>Drivers</label>
|
|
351
|
-
<MultiSelectionDropdownObj
|
|
352
|
-
key={dropdownKey2}
|
|
353
|
-
collectionName={collectionNames.DRIVERS}
|
|
354
|
-
label='Drivers'
|
|
355
|
-
valueName='id'
|
|
356
|
-
displayName='fullName'
|
|
357
|
-
onItemsSelected={driversSelected}
|
|
358
|
-
dropdownStyle={{color: '#000', backgroundColor: '#66ff66'}}
|
|
359
|
-
buttonStyle={{color: '#fff', backgroundColor: '#008000'}} />
|
|
360
|
-
</div>
|
|
361
|
-
|
|
362
|
-
{output &&
|
|
363
|
-
<div style={{ marginTop: '10px', padding: '5px' }}>
|
|
364
|
-
{output}
|
|
365
|
-
</div>
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
</div>
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
```
|
|
372
246
|
|
|
373
247
|
## License
|
|
374
248
|
MIT
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "ITA",
|
|
4
4
|
"description": "A React library providing customizable search dropdown components with single and multi-selection capabilities.",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.2",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "./dist/dropdowns-js.cjs.js",
|
|
9
9
|
"module": "./dist/dropdowns-js.es.js",
|