The namegen5 website.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5 KiB

3 years ago
  1. <script>
  2. /** @type {{value: string, text: string}[]} */
  3. export let options = []
  4. export let value = "";
  5. export let label = "Select";
  6. export let prefer = null;
  7. export let color = "#ffffff";
  8. export let bgcolor = "#444444";
  9. $: {
  10. if (options.length > 0 && !options.find(o => o.value === value)) {
  11. if (prefer != null) {
  12. const preferred = options.find(o => o.value.includes(prefer));
  13. if (preferred != null) {
  14. value = preferred.value;
  15. } else {
  16. value = options[0].value;
  17. }
  18. } else {
  19. value = options[0].value;
  20. }
  21. }
  22. }
  23. </script>
  24. <div class="selector" style="--color: {color || "#ffcc11"}; --bgcolor: {bgcolor || "#776655"}">
  25. <h2>{label}</h2>
  26. {#each options as option (option.value)}
  27. <div on:click={() => value = option.value} class="option" class:selected={option.value === value}>{option.text}</div>
  28. {/each}
  29. </div>
  30. <style>
  31. .selector {
  32. margin: auto;
  33. }
  34. h2 {
  35. font-size: 1.25em;
  36. margin-top: 1em;
  37. }
  38. .option {
  39. display: inline-block;
  40. margin: 0;
  41. padding: 0.5em 1.5ch;
  42. line-height: 1.1em;
  43. background: #333;
  44. border: 1px solid #000;
  45. cursor: pointer;
  46. }
  47. .option.selected {
  48. color: var(--color);
  49. background-color: var(--bgcolor);
  50. }
  51. .option:first-of-type {
  52. border-top-left-radius: 0.5em;
  53. border-bottom-left-radius: 0.5em;
  54. }
  55. .option:last-of-type {
  56. border-top-right-radius: 0.5em;
  57. border-bottom-right-radius: 0.5em;
  58. }
  59. </style>