summaryrefslogtreecommitdiff
path: root/src/components/jet/action/ExternalUrlAction.svelte
blob: e8a2ad6527363fa4cbde08407c1c991eb5a0a758 (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
<script lang="ts">
    import type { HTMLAnchorAttributes } from 'svelte/elements';
    import type { ExternalUrlAction } from '@jet-app/app-store/api/models';
    import ArrowIcon from '@amp/web-app-components/assets/icons/arrow.svg';
    import { getJetPerform } from '~/jet';

    type AllowedAnchorAttributes = Omit<
        HTMLAnchorAttributes,
        // The `href` attribute is not allowed because it will be provided
        // by the `ExternalUrlAction`
        'href'
    >;

    interface $$Props extends AllowedAnchorAttributes {
        destination: ExternalUrlAction;
        includeArrowIcon?: boolean;
    }

    const perform = getJetPerform();

    export let destination: ExternalUrlAction;
    export let includeArrowIcon: boolean = true;

    function handleClickAction() {
        perform(destination);
    }
</script>

<a
    {...$$restProps}
    data-test-id="external-link"
    href={destination.url}
    target="_blank"
    rel="nofollow noopener noreferrer"
    on:click={handleClickAction}
>
    <slot />
    {#if includeArrowIcon}
        <ArrowIcon class="external-link-arrow" aria-hidden="true" />
    {/if}
</a>

<style lang="scss">
    @use '@amp/web-shared-styles/sasskit-stylekit/ac-sasskit-config';
    @use 'ac-sasskit/core/locale' as *;

    a :global(.external-link-arrow) {
        @include rtl {
            transform: rotate(-90deg);
        }
    }
</style>