Skip to content

Instantly share code, notes, and snippets.

@matthew-ia
Created December 17, 2023 21:20
Show Gist options
  • Save matthew-ia/a882e1cd0522032341ccbcd6f6215f56 to your computer and use it in GitHub Desktop.
Save matthew-ia/a882e1cd0522032341ccbcd6f6215f56 to your computer and use it in GitHub Desktop.
Utility Classes as Properties Pattern (Svelte)
<script>
export let top = true;
export let bottom = true;
export let right = true;
export let left = true;
</script>
<div class:top class:bottom class:left class:right>
<slot/>
</div>
<style type="scss">
$y-padding: 20px;
$x-padding: 10px;
.top {
padding-top: $y-padding;
}
.bottom {
padding-bottom: $y-padding;
}
.left {
padding-left: $x-padding;
}
.right {
padding-right: $x-padding;
}
</style
<script>
import Box from "./Box.svelte";
const section2 = {
top: false,
left: false,
}
</script>
<Section bottom={false}>One</Section>
<Section {...section2}>Two</Section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment