Merge pull request #293 from reuters-graphics/jon-framer-search
Framer searchType
This commit is contained in:
commit
bb8977b017
3 changed files with 131 additions and 47 deletions
5
.changeset/easy-dryers-chew.md
Normal file
5
.changeset/easy-dryers-chew.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@reuters-graphics/graphics-components': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds a simple dropdown option to search embeds for Framer
|
||||||
50
src/components/Framer/Dropdown/index.svelte
Normal file
50
src/components/Framer/Dropdown/index.svelte
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<script lang="ts">
|
||||||
|
interface Props {
|
||||||
|
data: {
|
||||||
|
index: number;
|
||||||
|
embed: string;
|
||||||
|
title: string;
|
||||||
|
}[];
|
||||||
|
selected: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { data = [], selected = $bindable() }: Props = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label for="embed-options">Select an embed</label>
|
||||||
|
<select id="embed-options" bind:value={selected}>
|
||||||
|
{#each data as d (d.index)}
|
||||||
|
<option value={d.embed}>{d.title}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@use '../../../scss/mixins' as mixins;
|
||||||
|
|
||||||
|
label {
|
||||||
|
margin-bottom: 0.25rem;
|
||||||
|
display: inline-flex;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: #aaa;
|
||||||
|
@include mixins.font-sans;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background: none;
|
||||||
|
font-size: 1rem;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 0 !important;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
@include mixins.font-sans;
|
||||||
|
}
|
||||||
|
|
||||||
|
select:focus {
|
||||||
|
outline: none;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
import { width } from './stores';
|
import { width } from './stores';
|
||||||
import getUniqNames from './uniqNames';
|
import getUniqNames from './uniqNames';
|
||||||
import Typeahead from './Typeahead/index.svelte';
|
import Typeahead from './Typeahead/index.svelte';
|
||||||
|
import Dropdown from './Dropdown/index.svelte';
|
||||||
import ReutersGraphicsLogo from '../ReutersGraphicsLogo/ReutersGraphicsLogo.svelte';
|
import ReutersGraphicsLogo from '../ReutersGraphicsLogo/ReutersGraphicsLogo.svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -14,6 +15,7 @@
|
||||||
breakpoints?: number[];
|
breakpoints?: number[];
|
||||||
minFrameWidth?: number;
|
minFrameWidth?: number;
|
||||||
maxFrameWidth?: number;
|
maxFrameWidth?: number;
|
||||||
|
searchType?: 'dropdown' | 'typeahead';
|
||||||
}
|
}
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
|
@ -21,6 +23,7 @@
|
||||||
breakpoints = [330, 510, 660, 930, 1200],
|
breakpoints = [330, 510, 660, 930, 1200],
|
||||||
minFrameWidth = 320,
|
minFrameWidth = 320,
|
||||||
maxFrameWidth = 1200,
|
maxFrameWidth = 1200,
|
||||||
|
searchType = 'dropdown',
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
const getDefaultEmbed = (embeds: Props['embeds']) => {
|
const getDefaultEmbed = (embeds: Props['embeds']) => {
|
||||||
|
|
@ -71,37 +74,62 @@
|
||||||
<p>No embeds to show.</p>
|
<p>No embeds to show.</p>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<div id="typeahead-container">
|
{#if searchType === 'typeahead'}
|
||||||
<div class="embed-link">
|
<div id="typeahead-container">
|
||||||
<a
|
<div class="embed-link">
|
||||||
rel="external"
|
<a
|
||||||
target="_blank"
|
rel="external"
|
||||||
href={activeEmbed}
|
target="_blank"
|
||||||
title={activeEmbed}
|
href={activeEmbed}
|
||||||
>
|
title={activeEmbed}
|
||||||
Live link <Fa icon={faLink} />
|
>
|
||||||
</a>
|
Live link <Fa icon={faLink} />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<Typeahead
|
||||||
|
label="Select an embed"
|
||||||
|
value={embedTitles[embeds.indexOf(activeEmbed)] ||
|
||||||
|
embedTitles[activeEmbedIndex] ||
|
||||||
|
embedTitles[0]}
|
||||||
|
extract={(d) => embedTitles[d.index]}
|
||||||
|
data={embeds.map((embed, index) => ({ index, embed }))}
|
||||||
|
showDropdownOnFocus={true}
|
||||||
|
onselect={(detail) => {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
window.localStorage.setItem(
|
||||||
|
'framer-active-embed',
|
||||||
|
detail.original.embed
|
||||||
|
);
|
||||||
|
}
|
||||||
|
activeEmbed = detail.original.embed;
|
||||||
|
// activeEmbedIndex = detail.original.index;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Typeahead
|
{:else}
|
||||||
label="Select an embed"
|
<div id="dropdown-container">
|
||||||
value={embedTitles[embeds.indexOf(activeEmbed)] ||
|
<div>
|
||||||
embedTitles[activeEmbedIndex] ||
|
<div class="embed-link">
|
||||||
embedTitles[0]}
|
<a
|
||||||
extract={(d) => embedTitles[d.index]}
|
rel="external"
|
||||||
data={embeds.map((embed, index) => ({ index, embed }))}
|
target="_blank"
|
||||||
showDropdownOnFocus={true}
|
href={activeEmbed}
|
||||||
onselect={(detail) => {
|
title={activeEmbed}
|
||||||
if (typeof window !== 'undefined') {
|
>
|
||||||
window.localStorage.setItem(
|
Live link <Fa icon={faLink} />
|
||||||
'framer-active-embed',
|
</a>
|
||||||
detail.original.embed
|
</div>
|
||||||
);
|
</div>
|
||||||
}
|
<Dropdown
|
||||||
activeEmbed = detail.original.embed;
|
data={embeds.map((embed, index) => ({
|
||||||
// activeEmbedIndex = detail.original.index;
|
index,
|
||||||
}}
|
embed,
|
||||||
/>
|
title: embedTitles[index],
|
||||||
</div>
|
}))}
|
||||||
|
bind:selected={activeEmbed}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div id="preview-label" style="width:{$width}px;">
|
<div id="preview-label" style="width:{$width}px;">
|
||||||
<p>Preview</p>
|
<p>Preview</p>
|
||||||
|
|
@ -139,26 +167,27 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div#typeahead-container {
|
div#typeahead-container,
|
||||||
|
div#dropdown-container {
|
||||||
max-width: 660px;
|
max-width: 660px;
|
||||||
margin: 0 auto 15px;
|
margin: 0 auto 15px;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
div.embed-link {
|
||||||
div#typeahead-container div.embed-link {
|
position: absolute;
|
||||||
position: absolute;
|
top: 0;
|
||||||
top: 0;
|
right: 0;
|
||||||
right: 0;
|
display: inline-block;
|
||||||
display: inline-block;
|
z-index: 2;
|
||||||
z-index: 2;
|
a {
|
||||||
}
|
font-family: 'Knowledge', 'Source Sans Pro', Arial, sans-serif;
|
||||||
div#typeahead-container div.embed-link a {
|
color: #bbb;
|
||||||
font-family: 'Knowledge', 'Source Sans Pro', Arial, sans-serif;
|
font-size: 12px;
|
||||||
color: #bbb;
|
text-decoration: none !important;
|
||||||
font-size: 12px;
|
&:hover {
|
||||||
text-decoration: none !important;
|
color: #666;
|
||||||
}
|
}
|
||||||
div#typeahead-container div.embed-link a:hover {
|
}
|
||||||
color: #666;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
div#preview-label {
|
div#preview-label {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue