|
438 | 438 | {#snippet Example7()}
|
439 | 439 | <div class="p-5 bg-white space-y-6">
|
440 | 440 | <div>
|
441 |
| - <h6 class="font-semibold mb-3">Smart Source Selection:</h6> |
442 |
| - <p class="text-sm text-gray-600 mb-4"> |
| 441 | + <h6 class="govuk-heading-s">Smart Source Selection:</h6> |
| 442 | + <p class="govuk-body"> |
443 | 443 | This example demonstrates how to use the <code>sourceSelector</code> prop
|
444 | 444 | to intelligently choose between API and static options based on the search
|
445 | 445 | query. Try searching for:
|
446 | 446 | </p>
|
447 |
| - <ul class="text-sm text-gray-600 list-disc list-inside mb-4 space-y-1"> |
| 447 | + <ul class="govuk-list govuk-list--bullet"> |
448 | 448 | <li>
|
449 | 449 | <strong>Postcodes</strong> (e.g., "SW1A 1AA", "M1", "B1") → Uses API
|
450 | 450 | </li>
|
|
526 | 526 |
|
527 | 527 | // If it looks like a postcode (even partial), use API
|
528 | 528 | if (isLikelyPostcode(q)) {
|
529 |
| - console.log("🎯 Query looks like postcode, using API:", q); |
| 529 | + console.log("Query looks like postcode, using API:", q); |
530 | 530 | return "api";
|
531 | 531 | }
|
532 | 532 |
|
533 | 533 | // For everything else, use static options
|
534 |
| - console.log( |
535 |
| - "🎯 Query is not postcode-like, using static options:", |
536 |
| - q, |
537 |
| - ); |
| 534 | + console.log("Query is not postcode-like, using static options:", q); |
538 | 535 | return "options";
|
539 | 536 | }}
|
540 | 537 | />
|
541 | 538 | </div>
|
542 | 539 |
|
543 |
| - <div class="bg-blue-50 p-4 rounded-lg"> |
544 |
| - <h6 class="font-semibold mb-2 text-blue-800">How it works:</h6> |
545 |
| - <div class="text-sm text-blue-700 space-y-2"> |
| 540 | + <div class="govuk-inset-text"> |
| 541 | + <h6 class="govuk-heading-s govuk-!-margin-top-0">How it works:</h6> |
| 542 | + <div class="govuk-body"> |
546 | 543 | <p>
|
547 | 544 | <strong>sourceSelector</strong> is a function that receives the search
|
548 | 545 | query and available static options, then returns either "api" or "options"
|
|
551 | 548 | <p>
|
552 | 549 | <strong>Priority order:</strong>
|
553 | 550 | </p>
|
554 |
| - <ol class="list-decimal list-inside ml-4 space-y-1"> |
| 551 | + <ol class="govuk-list govuk-list--number"> |
555 | 552 | <li>Below <code>minLength</code> → "short" mode (no search)</li>
|
556 | 553 | <li>
|
557 | 554 | Your <code>sourceSelector</code> function → "api" or "options"
|
|
562 | 559 | This gives you full control over when to use API vs static options
|
563 | 560 | while maintaining the existing fallback behavior for edge cases.
|
564 | 561 | </p>
|
565 |
| - <p class="mt-3 p-2 bg-blue-100 rounded"> |
566 |
| - <strong>🎯 Smart Postcode Detection:</strong> The example uses robust UK |
567 |
| - postcode patterns that can detect both complete postcodes (e.g., "SW1A |
568 |
| - 1AA") and partial ones (e.g., "SW1", "M1A") as users type, automatically |
569 |
| - switching to API mode for postcode-like queries and static options for |
570 |
| - everything else. |
| 562 | + <p |
| 563 | + class="govuk-!-margin-top-4 govuk-!-padding-3 govuk-body govuk-!-font-weight-bold" |
| 564 | + > |
| 565 | + <strong>Smart Postcode Detection:</strong> The example uses robust UK postcode |
| 566 | + patterns that can detect both complete postcodes (e.g., "SW1A 1AA") and |
| 567 | + partial ones (e.g., "SW1", "M1A") as users type, automatically switching |
| 568 | + to API mode for postcode-like queries and static options for everything |
| 569 | + else. |
571 | 570 | </p>
|
572 | 571 | </div>
|
573 | 572 | </div>
|
|
0 commit comments