summaryrefslogtreecommitdiff
path: root/src/components/jet/shelf/HorizontalRuleShelf.svelte
blob: 3313ff22aec7057a17ecdbd48f0e928df93f68bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<script lang="ts" context="module">
    import type {
        HorizontalRule,
        HorizontalRuleStyle,
        Shelf,
    } from '@jet-app/app-store/api/models';

    export interface HorizontalRuleShelf extends Shelf {
        contentType: 'horizontalRule';
        items: [HorizontalRule];
    }

    export function isHorizontalRuleShelf(
        shelf: Shelf,
    ): shelf is HorizontalRuleShelf {
        return (
            shelf.contentType === 'horizontalRule' && Array.isArray(shelf.items)
        );
    }

    function horizontalRuleStyleToBorderStyle(
        style: HorizontalRuleStyle,
    ): string {
        return style.toLowerCase();
    }
</script>

<script lang="ts">
    import ShelfWrapper from '~/components/Shelf/Wrapper.svelte';
    import { colorAsString } from '~/utils/color';

    export let shelf: HorizontalRuleShelf;

    $: item = shelf.items[0];
    $: borderStyle = horizontalRuleStyleToBorderStyle(item.style);
</script>

<ShelfWrapper {shelf} withBottomPadding={false}>
    <hr
        style:color={colorAsString(item.color)}
        style:border-style={borderStyle}
    />
</ShelfWrapper>

<style>
    hr {
        display: block;
        height: 1px;
        border-width: 1px 0 0;
        border-color: currentColor;
        margin: 1em var(--bodyGutter);
        padding: 0;
    }
</style>