|
12 | 12 | import ColorPicker from "svelte-awesome-color-picker"; |
13 | 13 | import { generateField as genField } from "#/lib/modular"; |
14 | 14 |
|
| 15 | + const handleBackgroundChange = (event: CustomEvent<{ hex: string }>) => { |
| 16 | + if (event.detail.hex === undefined) { |
| 17 | + return; |
| 18 | + } |
| 19 | + colourContext.update((v) => { |
| 20 | + const newContext = { ...v, background: event.detail.hex }; |
| 21 | + if (v.background === v.board) { |
| 22 | + newContext.board = event.detail.hex; |
| 23 | + } |
| 24 | + return newContext; |
| 25 | + }); |
| 26 | + }; |
| 27 | +
|
15 | 28 | const boardTypes = new Map<SupportedBoards, string>([ |
16 | 29 | [ |
17 | 30 | "squares", |
|
443 | 456 |
|
444 | 457 | let previewDiv: HTMLDivElement; |
445 | 458 | onMount(() => { |
| 459 | + colourContext.update((v) => ({ ...v, board: v.board ?? v.background })); |
446 | 460 | const updatePreview = (state: RenderRepModified) => { |
447 | 461 | if (previewDiv !== undefined && previewDiv !== null) { |
448 | 462 | const toRender = JSON.parse( |
|
789 | 803 | <div class="control"> |
790 | 804 | <ColorPicker |
791 | 805 | bind:hex="{$colourContext.background}" |
792 | | - on:input="{(event) => |
793 | | - colourContext.update((v) => ({ |
794 | | - ...v, |
795 | | - background: event.detail.hex, |
796 | | - }))}" |
| 806 | + on:change="{handleBackgroundChange}" |
| 807 | + position="responsive" |
| 808 | + /> |
| 809 | + </div> |
| 810 | + </div> |
| 811 | + <div class="column"> |
| 812 | + <label class="label">Board</label> |
| 813 | + <div class="control"> |
| 814 | + <ColorPicker |
| 815 | + bind:hex="{$colourContext.board}" |
| 816 | + on:change="{(e) => |
| 817 | + e.detail.hex && |
| 818 | + colourContext.update((v) => ({ ...v, board: e.detail.hex }))}" |
797 | 819 | position="responsive" |
798 | 820 | /> |
799 | 821 | </div> |
| 822 | + <div class="help">Used for board fills</div> |
800 | 823 | </div> |
801 | 824 | <div class="column"> |
802 | 825 | <label class="label">Strokes</label> |
803 | 826 | <div class="control"> |
804 | 827 | <ColorPicker |
805 | 828 | bind:hex="{$colourContext.strokes}" |
806 | | - on:input="{(event) => |
807 | | - colourContext.update((v) => ({ |
808 | | - ...v, |
809 | | - strokes: event.detail.hex, |
810 | | - }))}" |
| 829 | + on:change="{(e) => |
| 830 | + e.detail.hex && |
| 831 | + colourContext.update((v) => ({ ...v, strokes: e.detail.hex }))}" |
811 | 832 | position="responsive" |
812 | 833 | /> |
813 | 834 | </div> |
|
817 | 838 | <div class="control"> |
818 | 839 | <ColorPicker |
819 | 840 | bind:hex="{$colourContext.labels}" |
820 | | - on:input="{(event) => |
821 | | - colourContext.update((v) => ({ |
822 | | - ...v, |
823 | | - labels: event.detail.hex, |
824 | | - }))}" |
| 841 | + on:change="{(e) => |
| 842 | + e.detail.hex && |
| 843 | + colourContext.update((v) => ({ ...v, labels: e.detail.hex }))}" |
825 | 844 | position="responsive" |
826 | 845 | /> |
827 | 846 | </div> |
|
831 | 850 | <div class="control"> |
832 | 851 | <ColorPicker |
833 | 852 | bind:hex="{$colourContext.fill}" |
834 | | - on:input="{(event) => |
835 | | - colourContext.update((v) => ({ |
836 | | - ...v, |
837 | | - fill: event.detail.hex, |
838 | | - }))}" |
| 853 | + on:change="{(e) => |
| 854 | + e.detail.hex && |
| 855 | + colourContext.update((v) => ({ ...v, fill: e.detail.hex }))}" |
839 | 856 | position="responsive" |
840 | 857 | /> |
841 | 858 | </div> |
|
0 commit comments