|
| 1 | +<script> |
| 2 | + import Radio from "svelte-radio"; |
| 3 | +
|
| 4 | + let value = "2"; |
| 5 | + let events = []; |
| 6 | +
|
| 7 | + function logEvent(type, detail) { |
| 8 | + events = [...events, { type, detail }]; |
| 9 | + } |
| 10 | +</script> |
| 11 | + |
| 12 | +<style> |
| 13 | + :global(.svelte-radio-group) { |
| 14 | + border: 2px solid #e0e0e0; |
| 15 | + padding: 1rem; |
| 16 | + } |
| 17 | +
|
| 18 | + :global(.svelte-radio) { |
| 19 | + margin-bottom: 0.5rem; |
| 20 | + } |
| 21 | +
|
| 22 | + :global(.svelte-radio label) { |
| 23 | + margin-left: 0.25rem; |
| 24 | + } |
| 25 | +
|
| 26 | + h2 { |
| 27 | + font-size: 0.75rem; |
| 28 | + font-weight: 800; |
| 29 | + text-transform: uppercase; |
| 30 | + letter-spacing: 0.1rem; |
| 31 | + margin-bottom: 0.5rem; |
| 32 | + margin-top: 1rem; |
| 33 | + } |
| 34 | +
|
| 35 | + .padding { |
| 36 | + padding: 1rem; |
| 37 | + } |
| 38 | +
|
| 39 | + .empty { |
| 40 | + padding: 0.5rem 0; |
| 41 | + color: #6f6f6f; |
| 42 | + } |
| 43 | +
|
| 44 | + ul { |
| 45 | + list-style: none; |
| 46 | + } |
| 47 | +
|
| 48 | + li { |
| 49 | + color: #393939; |
| 50 | + padding: 0.5rem 0; |
| 51 | + border-bottom: 1px solid #e0e0e0; |
| 52 | + } |
| 53 | +
|
| 54 | + .tag { |
| 55 | + font-size: 0.875rem; |
| 56 | + padding: 0.25rem; |
| 57 | + color: #393939; |
| 58 | + background-color: #f4f4f4; |
| 59 | + border-radius: 0.25rem; |
| 60 | + } |
| 61 | +
|
| 62 | + .tag pre { |
| 63 | + margin: 0.5rem 0; |
| 64 | + padding: 0.5rem 1rem; |
| 65 | + border-radius: 0.25rem; |
| 66 | + background-color: #f4f4f4; |
| 67 | + } |
| 68 | +
|
| 69 | + .tag:before { |
| 70 | + content: "“"; |
| 71 | + } |
| 72 | +
|
| 73 | + .tag:after { |
| 74 | + content: "”"; |
| 75 | + } |
| 76 | +
|
| 77 | + button { |
| 78 | + background: none; |
| 79 | + border: 0; |
| 80 | + cursor: pointer; |
| 81 | + font: inherit; |
| 82 | + font-size: 0.875rem; |
| 83 | + padding: 0.5rem 1rem; |
| 84 | + border-radius: 0.25rem; |
| 85 | + outline: 2px solid #e0e0e0; |
| 86 | + margin-right: 0.5rem; |
| 87 | + margin-bottom: 0.25rem; |
| 88 | + } |
| 89 | +
|
| 90 | + button:active { |
| 91 | + outline-color: #0f62fe; |
| 92 | + color: #0f62fe; |
| 93 | + } |
| 94 | +
|
| 95 | + button:focus { |
| 96 | + outline-color: #0f62fe; |
| 97 | + } |
| 98 | +
|
| 99 | + .buttons { |
| 100 | + margin-top: 1rem; |
| 101 | + } |
| 102 | +</style> |
| 103 | + |
| 104 | +<svelte:head> |
| 105 | + <title>svelte-radio</title> |
| 106 | +</svelte:head> |
| 107 | + |
| 108 | +<Radio.Group |
| 109 | + bind:value |
| 110 | + on:change={({ detail }) => { |
| 111 | + logEvent('change', detail); |
| 112 | + }}> |
| 113 | + <Radio.Button label="Label 1" value="1" /> |
| 114 | + <Radio.Button label="Label 2" value="2" /> |
| 115 | + <Radio.Button label="Label 3" value="3" /> |
| 116 | +</Radio.Group> |
| 117 | + |
| 118 | +<div class="padding"> |
| 119 | + <h2>Bound value</h2> |
| 120 | + <span class="tag">{value}</span> |
| 121 | +</div> |
| 122 | + |
| 123 | +<div class="buttons"> |
| 124 | + <button |
| 125 | + type="button" |
| 126 | + on:click={() => { |
| 127 | + value = '1'; |
| 128 | + }}> |
| 129 | + Set value to 1 |
| 130 | + </button> |
| 131 | + |
| 132 | +</div> |
| 133 | + |
| 134 | +<ul class="padding"> |
| 135 | + <h2>Events</h2> |
| 136 | + {#if events.length === 0} |
| 137 | + <div class="empty">No events.</div> |
| 138 | + {/if} |
| 139 | + {#each events as event} |
| 140 | + <li> |
| 141 | + {event.type} |
| 142 | + <span class="tag"> |
| 143 | + <pre>{JSON.stringify(event.detail, null, 2)}</pre> |
| 144 | + </span> |
| 145 | + </li> |
| 146 | + {/each} |
| 147 | +</ul> |
0 commit comments