-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement a configuration dropdown to select a query language
- Loading branch information
Showing
7 changed files
with
250 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/lib/components/controls/selectQueryLanguage/SelectQueryLanguage.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import '../../../styles'; | ||
|
||
.jse-select-query-language { | ||
position: relative; | ||
width: 32px; | ||
|
||
.jse-select-query-language-container { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
display: flex; | ||
flex-direction: column; | ||
box-shadow: $box-shadow; | ||
|
||
.jse-query-language { | ||
@include jsoneditor-button; | ||
|
||
text-align: left; | ||
padding: $padding 2 * $padding; | ||
white-space: nowrap; | ||
color: white; | ||
background: $dark-gray; | ||
|
||
$gray-highlight: lighten($dark-gray, 5%); | ||
|
||
&:hover { | ||
background: $gray-highlight; | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/lib/components/controls/selectQueryLanguage/SelectQueryLanguage.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script> | ||
import Icon from 'svelte-awesome' | ||
import { faCheckSquare, faSquare } from '@fortawesome/free-regular-svg-icons' | ||
/** @type {QueryLanguage[]} */ | ||
export let queryLanguages | ||
/** @type {string} */ | ||
export let queryLanguageId | ||
/** @type {(queryLanguageId: string) => void} */ | ||
export let onChangeQueryLanguage | ||
function handleChangeQueryLanguage(newQueryLanguageId) { | ||
queryLanguageId = newQueryLanguageId | ||
onChangeQueryLanguage(newQueryLanguageId) | ||
} | ||
</script> | ||
|
||
<div class="jse-select-query-language"> | ||
<div class="jse-select-query-language-container"> | ||
{#each queryLanguages as queryLanguage} | ||
<button | ||
on:click={() => handleChangeQueryLanguage(queryLanguage.id)} | ||
class="jse-query-language" | ||
class:selected={queryLanguage.id === queryLanguageId} | ||
title={`Select ${queryLanguage.name} as query language`} | ||
> | ||
{#if queryLanguage.id === queryLanguageId} | ||
<Icon data={faCheckSquare} /> | ||
{:else} | ||
<Icon data={faSquare} /> | ||
{/if} | ||
{queryLanguage.name} | ||
</button> | ||
{/each} | ||
</div> | ||
</div> | ||
|
||
<style src="./SelectQueryLanguage.scss"></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
vertical-align: middle; | ||
} | ||
|
||
button.config, | ||
button.close { | ||
border: none; | ||
background: transparent; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { getContext } from 'svelte' | ||
import Icon from 'svelte-awesome' | ||
import { faCog, faTimes } from '@fortawesome/free-solid-svg-icons' | ||
import SelectQueryLanguage from '$lib/components/controls/selectQueryLanguage/SelectQueryLanguage.svelte' | ||
/** @type {QueryLanguage[]} */ | ||
export let queryLanguages | ||
/** @type {string} */ | ||
export let queryLanguageId | ||
/** @type {(queryLanguageId: string) => void} */ | ||
export let onChangeQueryLanguage | ||
let refConfigButton | ||
const { close } = getContext('simple-modal') | ||
const { openAbsolutePopup, closeAbsolutePopup } = getContext('absolute-popup') | ||
function openConfig() { | ||
const props = { | ||
queryLanguages, | ||
queryLanguageId, | ||
onChangeQueryLanguage: (selectedQueryLanguage) => { | ||
closeAbsolutePopup() | ||
onChangeQueryLanguage(selectedQueryLanguage) | ||
} | ||
} | ||
openAbsolutePopup(SelectQueryLanguage, props, { | ||
position: 'bottom', | ||
offsetTop: -2, | ||
offsetLeft: 0, | ||
anchor: refConfigButton, | ||
closeOnOuterClick: true | ||
}) | ||
} | ||
</script> | ||
|
||
<div class="header"> | ||
<div class="title">Transform</div> | ||
{#if queryLanguages.length > 1} | ||
<button | ||
bind:this={refConfigButton} | ||
type="button" | ||
class="config" | ||
on:click={openConfig} | ||
title="Select a query language" | ||
> | ||
<Icon data={faCog} /> | ||
</button> | ||
{/if} | ||
<button type="button" class="close" on:click={close}> | ||
<Icon data={faTimes} /> | ||
</button> | ||
</div> | ||
|
||
<style src="./Header.scss"></style> |
Oops, something went wrong.