summaryrefslogtreecommitdiff
path: root/src/components/LaunchNativeButton.svelte
blob: eb7942b50f7583184d60fd0008aaa7b3cb9d9435 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script lang="ts">
    import ArrowIcon from '@amp/web-app-components/assets/icons/arrow.svg';
    import LineClamp from '@amp/web-app-components/src/components/LineClamp/LineClamp.svelte';
    import { getJet } from '~/jet';
    import { getI18n } from '~/stores/i18n';
    import { launchAppOnMac } from '~/utils/launch-client';

    export let url: string;

    const i18n = getI18n();
    const jet = getJet();

    function handleButtonClick(event: MouseEvent) {
        // Need to call both event.preventDefault() and event.stopPropagation()
        // to prevent navigation to the production page on web
        event.preventDefault();
        event.stopPropagation();

        if (url) {
            launchAppOnMac(url);
            jet.recordCustomMetricsEvent({
                eventType: 'click',
                targetId: 'OpenInMacAppStore',
                targetType: 'button',
                actionType: 'open',
            });
        }
    }
</script>

<button
    class="get-button blue"
    aria-label={$i18n.t('ASE.Web.AppStore.CTA.MacAppStore.AX')}
    on:click={handleButtonClick}
>
    <LineClamp clamp={1}>
        {$i18n.t('ASE.Web.AppStore.CTA.MacAppStore.Action')}
        <span>
            {$i18n.t('ASE.Web.AppStore.CTA.MacAppStore.App')}
        </span>
    </LineClamp>
    <ArrowIcon class="external-link-arrow" aria-hidden="true" />
</button>

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

    button {
        display: inline-flex;
    }

    button span {
        font-weight: 500;
    }

    button :global(.external-link-arrow) {
        align-self: center;
        width: var(--launch-native-button-arrow-size, 9px);
        height: var(--launch-native-button-arrow-size, 9px);
        padding-top: 1px;
        margin-inline-start: 4px;
        fill: var(--systemPrimary-onDark);

        @include rtl {
            transform: rotate(-90deg);
        }
    }
</style>