Skip to content

Commit

Permalink
refactor: button reusable component (#137)
Browse files Browse the repository at this point in the history
Co-authored-by: Jérôme <[email protected]>
  • Loading branch information
itupix and Jérôme authored Dec 10, 2021
1 parent e1d8885 commit 00aeab6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 83 deletions.
48 changes: 48 additions & 0 deletions src/components/Button/Button.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
let className = '';
export { className as class };
export let danger:boolean = false;
export let clear:boolean = false;
export let disabled:boolean = false;
export let light:boolean = false;
export let type:string = '';
const dispatch = createEventDispatcher();
const onClick = (event) => {
event.preventDefault();
dispatch('click');
}
</script>


<button {type} class={className} class:danger class:clear class:light on:click={onClick} {disabled}>
<slot/>
</button>

<style>
button {
display: flex;
align-items: center;
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.danger {
background-color: red;
}
.clear {
background-color: #333;
}
.light {
background-color: transparent;
}
</style>
1 change: 1 addition & 0 deletions src/components/Button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Button.svelte';
27 changes: 4 additions & 23 deletions src/components/CustomListSettings/CustomListSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { CustomListType, PullRequestType } from 'models/skizzle';
import { remote } from 'shared/remote';
import { client } from 'shared/stores/authentication.store';
import Button from 'components/Button';
import {
customLists,
notifications,
Expand Down Expand Up @@ -207,9 +208,9 @@
</div>
</div>
<div class="action">
<button class="cancel" on:click={() => onDone()}>Cancel</button>
<button class="cta" on:click={() => saveSettings()} disabled={!customList.name}
>Save</button
<Button light on:click={() => onDone()}>Cancel</Button>
<Button on:click={() => saveSettings()} disabled={!customList.name}
>Save</Button
>
</div>

Expand Down Expand Up @@ -268,26 +269,6 @@
justify-content: flex-end;
}
.cta {
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.cancel {
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
cursor: pointer;
border: none;
background-color: transparent;
transition: opacity linear 0.2s;
}
:global(.isListDisplayed) {
margin-bottom: 0.2rem;
}
Expand Down
28 changes: 5 additions & 23 deletions src/components/ImportExport/ImportExport.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import AccountTitle from 'components/AccountTitle';
import Button from 'components/Button';
import Icons from 'components/icons';
import Tabs from 'components/Tabs';
import type { RepositoryType } from 'models/skizzle';
Expand Down Expand Up @@ -107,12 +108,12 @@
</p>
<textarea bind:value={code} placeholder="Paste here your JSON code" />
<div class="bar">
<input
<Button
disabled={!isJson(code)}
type="submit"
class="import-button"
value="Import repositories"
/>
>
Import repositories
</Button>
</div>
</form>
{/if}
Expand All @@ -131,25 +132,6 @@
background-color: #2b2b2b;
}
.import-button {
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
cursor: pointer;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.import-button:disabled {
opacity: 0.5;
}
.import-button:not(:disabled):hover {
opacity: 0.8;
}
.intro {
margin-bottom: 1rem;
font-size: 0.8rem;
Expand Down
57 changes: 20 additions & 37 deletions src/components/Settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import { remote } from 'shared/remote';
import { isElectron, settings } from 'shared/stores/default.store';
import { onMount } from 'svelte';
import Button from 'components/Button';
let currentPlatform: string = navigator.platform === 'Win32' ? 'Windows' : 'macOS';
let isWarningDisplayed: boolean = false;
Expand Down Expand Up @@ -70,7 +71,7 @@
{progressState.percent.toFixed(0)}%
</p>
{:else}
<button class="button" on:click={checkForUpdateRestart}>Restart Skizzle</button>
<Button class="button" on:click={checkForUpdateRestart}>Restart Skizzle</Button>
{/if}
</div>
</div>
Expand Down Expand Up @@ -150,15 +151,15 @@
title="Cache"
intro="If you encounter any dysfunctional behavior from Skizzle, cleaning the application cache is maybe necessary."
>
<button class="button" on:click={() => SkizzleCache.clear()}>Clean the cache</button>
<Button on:click={() => SkizzleCache.clear()}>Clean the cache</Button>
</Fieldset>

<Fieldset title="Reset application" intro="Reset all application settings and data.">
<button
class="button danger"
on:click|preventDefault={() => {
<Button
danger
on:click={() => {
isWarningDisplayed = true;
}}>Reset application</button
}}>Reset application</Button
>
</Fieldset>

Expand All @@ -175,16 +176,18 @@
Github or Azure accounts.
</p>
<div class="bar">
<button
class="button danger"
on:click|preventDefault={() => remote.clearApplicationsData()}
><Icons.Trash color="#fff" /> Yes, reset Skizzle.</button
<Button
danger
class="button"
on:click={() => remote.clearApplicationsData()}
><Icons.Trash color="#fff" /> Yes, reset Skizzle.</Button
>
<button
class="button clear"
on:click|preventDefault={() => {
<Button
clear
class="button"
on:click={() => {
isWarningDisplayed = false;
}}>Cancel</button
}}>Cancel</Button
>
</div>
</Modale>
Expand Down Expand Up @@ -280,30 +283,14 @@
font-size: 0.8rem;
}
.update .button {
.update :global(.button) {
position: absolute;
right: 1rem;
top: 50%;
transform: translateY(-50%);
}
.button {
display: flex;
align-items: center;
padding: 0.5rem 1rem;
color: #fff;
font-size: 1rem;
border-radius: 4px;
border: none;
background-color: var(--color);
transition: opacity linear 0.2s;
}
.danger {
background-color: red;
}
.progress {
text-align: center;
background-color: #666;
Expand Down Expand Up @@ -335,11 +322,7 @@
margin-top: 1rem;
}
.bar .button {
.bar :global(.button) {
margin: 0 0.5rem;
}
.button.clear {
background-color: #333;
}
</style>

0 comments on commit 00aeab6

Please sign in to comment.