Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CustomDiffSection component in page #12

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import AdditionalMarkSection from '$sample/sections/additionalMark/AdditionalMarkSection.svelte';
import RemovedMarkSection from '$sample/sections/removedMark/RemovedMarkSection.svelte';
import AddAndRemoveMarkSection from '$sample/sections/addAndRemoveMark/AddAndRemoveMarkSection.svelte';
import CustomDiffSection from '$sample/sections/custom/CustomDiffSection.svelte';
</script>

<SyntaxHighlightSection />
<AdditionalMarkSection />
<RemovedMarkSection />
<AddAndRemoveMarkSection />
<CustomDiffSection />
1 change: 1 addition & 0 deletions src/sample/header/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { base } from '$app/paths';
</script>

<header translate="no">
<h1>Svelte Diff Highlighting</h1>
<nav>
Expand Down
138 changes: 138 additions & 0 deletions src/sample/sections/custom/CustomDiffSection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<script lang="ts">
import Highlighted from '$lib/ui/Highlighted.svelte';
import 'highlight.js/styles/xcode.css';
import BorderedSection from '$sample/components/section/BorderedSection.svelte';
import SectionTitleText from '$sample/components/text/SectionTitleText.svelte';

let oldText = `func fizzbuzz(number: Int) -> String {
if number % 15 == 0 {
return "FizzBuzz"
}
if number % 3 == 0 {
return "Fizz"
}
if number % 5 == 0 {
return "Buzz"
}
return String(number)
}`;
let newText = `extension Int {
divisible(by divisor: Int) -> Bool {
self % divisor == 0
}
}

func fizzbuzz(number: Int) -> String {
if number.divisible(by: 15) {
return "FizzBuzz"
}
if number.divisible(by: 3) {
return "Fizz"
}
if number.divisible(by: 5) {
return "Buzz"
}
return String(number)
}`;
</script>

<BorderedSection>
<div class="add-and-remove-mark-section">
<div class="title">
<SectionTitleText>Add and Remove Code Diff</SectionTitleText>
</div>
<div class="targets">
<div class="old target">
<h3>Old Code</h3>
<div class="code">
<textarea bind:value={oldText} />
</div>
</div>
<div class="new target">
<h3>New Code</h3>
<div class="code">
<textarea bind:value={newText} />
</div>
</div>
</div>

<div class="diff">
<h3>Difference</h3>
<div class="code">
<Highlighted setNumber text={newText} old={oldText} />
</div>
</div>
</div>
</BorderedSection>

<style>
.add-and-remove-mark-section {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;

& > .title {
margin-bottom: 32px;
width: 100%;
}

& > .targets {
width: 90svw;
display: flex;
align-items: flex-start;
justify-content: space-between;
margin-bottom: 24px;

& > .target {
width: calc(45svw - 6px);

& > h3 {
width: 100%;
font-size: 18px;
font-weight: 600;
margin-bottom: 4px;
}

& > .code {
font-family: var(--code-font-family), monospace;
font-size: 14px;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
box-shadow: var(--box-shadow);
padding: 24px;
border-radius: 4px;

& > textarea {
width: 100%;
height: 100%;
min-height: 300px;
}
}
}
}

& > .diff {
width: 90svw;
& > h3 {
width: 100%;
font-size: 18px;
font-weight: 600;
margin-bottom: 4px;
}

& > .code {
width: 100%;
font-family: var(--code-font-family), monospace;
font-size: 14px;
font-optical-sizing: auto;
font-weight: 400;
font-style: normal;
max-width: 90svw;
box-shadow: var(--box-shadow);
padding: 12px 0;
}
}
}
</style>