Skip to content

Commit

Permalink
fix: mobile fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperorb committed Mar 31, 2024
1 parent bbf0a52 commit e021eb1
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 34 deletions.
91 changes: 70 additions & 21 deletions src/lib/components/pages/Playground/Playground.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script lang="ts">
import { browser } from '$app/environment';
import type { PlaygroundSchema } from '$lib/playground/playground.schema';
import type { BrowserSupportDataForMethod } from '$lib/types/BrowserSupport.types';
import Highlight from 'svelte-highlight';
import typescript from 'svelte-highlight/languages/typescript';
Expand All @@ -25,18 +27,21 @@
import { validateAndUpdateSchema } from '$lib/playground/validate';
import { copyCode, copyToClipboard } from '$lib/utils/copy-to-clipboard';
import { schemas, type SchemaKeys } from '$lib/playground/schemas';
import { onMount } from 'svelte';
import { onDestroy, onMount } from 'svelte';
import { numberFormatSchema } from '$lib/playground/schemas/numberFormat.schema';
import { trackEvent } from '$lib/utils/analytics';
import BrowserSupport from '$lib/components/ui/BrowserSupport/BrowserSupport.svelte';
import Grid from '$lib/components/ui/Grid.svelte';
import { getMessages } from '$lib/i18n/util';
const m = getMessages();
export let data: { [key: string]: BrowserSupportDataForMethod };
export let locale: string;
const m = getMessages();
const matchMedia = browser ? window.matchMedia('(min-width: 630px)') : null;
$: isDesktop = Boolean(matchMedia?.matches);
$: schema = validateAndUpdateSchema(numberFormatSchema);
$: browserSupportData = schema ? { ...data[schema.method] } : { ...data.NumberFormat };
Expand Down Expand Up @@ -96,6 +101,21 @@
method: schema.method
});
};
const onMatchMediaChange = (event: MediaQueryListEventMap['change']) => {
isDesktop = event.matches;
};
onMount(() => {
if (browser && matchMedia) {
matchMedia.addEventListener('change', onMatchMediaChange);
}
});
onDestroy(() => {
if (browser && matchMedia) {
matchMedia.removeEventListener('change', onMatchMediaChange);
}
});
</script>

{#if schema}
Expand All @@ -109,19 +129,7 @@
<Spacing />
<PlaygroundInput bind:locale {schema} {onChangeSchema} {onChangeDate} {onInput} />
<Spacing />
<PlaygroundOptions
bind:support={browserSupportData.optionsSupport}
{schema}
{onChangeOption}
/>
<Spacing />
<PlaygroundSecondaryFormatters
bind:support={browserSupportData.formattersSupport}
secondaryFormatters={schemaToSecondaryFormattersOutput(schema, locale)}
/>
</div>
<div class="output">
<div class="output-inner">
{#if !isDesktop}
<h2>{m.output()}</h2>
<Spacing size={2} />
<Highlight language={typescript} code={schemaToPrimaryFormatterOutput(schema, locale)} />
Expand All @@ -135,14 +143,51 @@
<div class="copy-code">
<Button onClick={copy}>{m.copyCode()} <CopyToClipboard /></Button>
</div>
<Spacing size={2} />
{/if}
<PlaygroundOptions
bind:support={browserSupportData.optionsSupport}
{schema}
{onChangeOption}
/>
<Spacing />
{#if !isDesktop}
<h2>{m.resolvedOptions()}</h2>
<Spacing size={2} />
<div>
<Highlight language={typescript} code={schemaToResolvedOptions(schema, locale)} />
</div>
</div>
{/if}
<Spacing />
<PlaygroundSecondaryFormatters
bind:support={browserSupportData.formattersSupport}
secondaryFormatters={schemaToSecondaryFormattersOutput(schema, locale)}
/>
</div>
{#if isDesktop}
<div class="output">
<div class="output-inner">
<h2>{m.output()}</h2>
<Spacing size={2} />
<Highlight language={typescript} code={schemaToPrimaryFormatterOutput(schema, locale)} />
<Spacing />
<h2>{m.code()}</h2>
<Spacing size={2} />
<div class="highlight">
<Highlight language={typescript} code={schemaToCode(schema, locale)} />
</div>
<Spacing size={2} />
<div class="copy-code">
<Button onClick={copy}>{m.copyCode()} <CopyToClipboard /></Button>
</div>
<Spacing size={2} />
<h2>{m.resolvedOptions()}</h2>
<Spacing size={2} />
<div>
<Highlight language={typescript} code={schemaToResolvedOptions(schema, locale)} />
</div>
</div>
</div>
{/if}
</div>
{/if}

Expand All @@ -151,7 +196,6 @@
padding-right: 0;
}
.output {
padding: var(--spacing-4);
padding-top: var(--spacing-5);
border-top-left-radius: 4px;
}
Expand All @@ -161,10 +205,15 @@
}
.columns {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-columns: 1fr;
gap: var(--spacing-4);
position: relative;
}
@media screen and (min-width: 630px) {
.columns {
grid-template-columns: 1fr 1fr;
}
}
@media screen and (min-width: 900px) {
.columns {
grid-template-columns: 2fr 1fr;
Expand Down
5 changes: 0 additions & 5 deletions src/lib/components/pages/Playground/PlaygroundOptions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@
grid-template-columns: 1fr 1fr;
}
}
h2 {
font-size: 1.25rem;
display: inline-block;
}
.radios {
display: flex;
align-items: center;
Expand Down
24 changes: 17 additions & 7 deletions src/lib/components/ui/BrowserSupport/BrowserSupport.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@

{#if data}
<Details fullWidth={false}>
<div slot="summary" class="summary">
<p>{m.browserSupport()}</p>
<SupportLabel bind:support={data.coverage} {hideFullSupport} />
</div>
<svelte:fragment slot="summary">
<div class="header">
<p>{m.browserSupport()}</p>
<SupportLabel bind:support={data.coverage} {hideFullSupport} />
</div>
</svelte:fragment>
<BrowserSupportGrid bind:data={data.support} />
</Details>
{/if}

<style>
.summary {
.header {
width: 100%;
display: flex;
gap: var(--spacing-4);
margin-right: var(--spacing-4);
flex-direction: column;
justify-content: space-between;
}
@media screen and (min-width: 500px) {
.header {
flex-direction: row;
align-items: center;
gap: var(--spacing-2);
}
}
</style>
2 changes: 1 addition & 1 deletion src/lib/components/ui/OptionSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
flex-direction: column;
gap: var(--spacing-2);
}
@media screen and (min-width: 500px) {
@media screen and (min-width: 900px) {
.header {
flex-direction: row;
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/ui/details/Details.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
.summary-title {
user-select: none;
width: 100%;
margin-right: var(--spacing-2);
}
.summary-icon {
pointer-events: none;
Expand Down

0 comments on commit e021eb1

Please sign in to comment.