Skip to content

Commit

Permalink
Reorder lanes (without bringing in a drag-and-drop library yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 26, 2024
1 parent 94474a3 commit eff5374
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/routes/cross_section/proposed/CrossSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@
lanesLeftToRight.splice(i, 1);
lanesLeftToRight = lanesLeftToRight;
}
function moveLeft(i: number) {
[lanesLeftToRight[i - 1], lanesLeftToRight[i]] = [
lanesLeftToRight[i],
lanesLeftToRight[i - 1],
];
}
function moveRight(i: number) {
[lanesLeftToRight[i + 1], lanesLeftToRight[i]] = [
lanesLeftToRight[i],
lanesLeftToRight[i + 1],
];
}
</script>

<SecondaryButton on:click={addNewLane}>Add</SecondaryButton>

<div style="display: flex; flex-direction: row">
{#each lanesLeftToRight as lane, i (i)}
<LaneCard bind:value={lane} on:delete={() => deleteLane(i)} />
<LaneCard
bind:value={lane}
on:delete={() => deleteLane(i)}
on:moveLeft={() => moveLeft(i)}
on:moveRight={() => moveRight(i)}
isFirst={i == 0}
isLast={i == lanesLeftToRight.length - 1}
/>
{/each}
</div>
16 changes: 14 additions & 2 deletions src/routes/cross_section/proposed/LaneCard.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { WarningButton, Select } from "govuk-svelte";
import { SecondaryButton, WarningButton, Select } from "govuk-svelte";
import { laneTypes } from "../data";
export let value: string;
export let isFirst: boolean;
export let isLast: boolean;
let dispatch = createEventDispatcher<{
delete: void;
moveLeft: void;
moveRight: void;
}>();
function pairs(list: string[]): [string, string][] {
Expand All @@ -16,7 +20,15 @@

<div>
<Select label="Lane type" emptyOption choices={pairs(laneTypes)} bind:value />
<WarningButton on:click={() => dispatch("delete")}>Delete</WarningButton>
<div style="display: flex; justify-content: space-between">
<SecondaryButton disabled={isFirst} on:click={() => dispatch("moveLeft")}>
&larr;
</SecondaryButton>
<WarningButton on:click={() => dispatch("delete")}>Delete</WarningButton>
<SecondaryButton disabled={isLast} on:click={() => dispatch("moveRight")}>
&rarr;
</SecondaryButton>
</div>
</div>

<style>
Expand Down

0 comments on commit eff5374

Please sign in to comment.