Skip to content

Commit ab90391

Browse files
authored
212 bug misc button bugs (#236)
## Goal The goal of this PR is streamline our buttons to use SG. Closes #212 ## Discussion - Use SG as much as possible - Remove unused code - Improve button components and custom styles where possible ## How To Test the Changes 1. Clone the pr branch 2. Delete node modules and package lock as there may be caching issues 3. `npm i` 4. `npm run dev` -> See buttons looking and functioning as expected.
1 parent ca9b9f9 commit ab90391

File tree

20 files changed

+600
-631
lines changed

20 files changed

+600
-631
lines changed

package-lock.json

Lines changed: 534 additions & 554 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"type": "module",
6464
"dependencies": {
6565
"@frequency-chain/api-augment": "^1.13.2",
66-
"@frequency-chain/style-guide": "^0.1.30",
66+
"@frequency-chain/style-guide": "^0.1.32",
6767
"@polkadot/api": "^15.9.2",
6868
"@polkadot/extension-dapp": "^0.58.8",
6969
"@polkadot/extension-inject": "^0.58.8",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { logout } from '$lib/stores';
3+
import ButtonNoFill from './ButtonNoFill.svelte';
34
let { cancelText = 'Cancel' } = $props();
45
</script>
56

6-
<a href="/" class="btn-no-fill text-sm" data-testid="back-home" onclick={logout}>{cancelText}</a>
7+
<ButtonNoFill href="/" data-testid="back-home" onclick={logout}>{cancelText}</ButtonNoFill>

src/components/atoms/Button.svelte

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script lang="ts">
2+
import { cn } from '$lib/utils';
3+
import type { HTMLAttributes } from 'svelte/elements';
4+
5+
interface Props extends HTMLAttributes<HTMLButtonElement | HTMLAnchorElement> {
6+
href?: string;
7+
children?: import('svelte').Snippet;
8+
}
9+
10+
let { href, children, ...rest }: Props = $props();
11+
</script>
12+
13+
{#if href}
14+
<a {...rest} {href} class={cn('hover:text-teal underline; cursor-pointer text-sm', rest.class)}>
15+
{@render children?.()}
16+
</a>
17+
{:else}
18+
<button {...rest} class={cn('hover:text-teal underline; cursor-pointer text-sm', rest.class)}>
19+
{@render children?.()}
20+
</button>
21+
{/if}

src/components/features/BecomeProviderNextSteps/CreateMsa.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
controlled by the selected Transaction Signing Address above.
5757
</p>
5858
<div class="flex w-[350px] items-end justify-between">
59-
<Button type="primary" onclick={doCreateMsa} disabled={isInProgress}>
59+
<Button onclick={doCreateMsa} disabled={isInProgress}>
6060
{#if isInProgress}
6161
<LoadingIcon />
6262
{:else}

src/components/features/BecomeProviderNextSteps/CreateProvider.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,7 @@
8080
/>
8181
</div>
8282
<div class="flex items-end justify-between">
83-
<Button
84-
type="primary"
85-
id="create-provider-btn"
86-
class="disabled:bg-gray3 disabled:text-white disabled:hover:shadow-none"
87-
onclick={doCreateProvider}
88-
disabled={isInProgress}
89-
>
83+
<Button id="create-provider-btn" onclick={doCreateProvider} disabled={isInProgress}>
9084
{#if isInProgress}
9185
<LoadingIcon />
9286
{:else}

src/components/features/BecomeProviderNextSteps/RequestToBeProvider.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import LoadingIcon from '$lib/assets/LoadingIcon.svelte';
1111
import { getMsaInfo } from '$lib/polkadotApi';
1212
import ActivityLogPreviewItem from '$features/ActivityLogItem/ActivityLogItem.svelte';
13+
import { Button } from '@frequency-chain/style-guide';
1314
1415
let { hasRequestedToBeProvider = $bindable(), ...props } = $props();
1516
@@ -69,18 +70,17 @@
6970
/>
7071
</div>
7172
<div class="flex w-[350px] justify-between">
72-
<button
73+
<Button
7374
onclick={doProposeToBeProvider}
7475
disabled={newProviderName === '' || isInProgress}
7576
id="request-2b-provider-btn"
76-
class="btn-primary"
7777
>
7878
{#if isInProgress}
7979
<LoadingIcon />
8080
{:else}
8181
Request To Be Provider
8282
{/if}
83-
</button>
83+
</Button>
8484
<BackHomeButton />
8585
</div>
8686
</form>

src/components/features/Capacity/Capacity.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
</script>
4242

4343
<ListCard title="Capacity" list={capacityList} errorMessage={errMsg}>
44-
<Button size="sm" type="primary" class="btn-primary" onClick={() => (showStakeToProvider = true)}
45-
>Stake to Provider</Button
46-
>
44+
<Button size="sm" onclick={() => (showStakeToProvider = true)}>Stake to Provider</Button>
4745
<Stake isOpen={showStakeToProvider} close={() => (showStakeToProvider = false)} />
4846
</ListCard>

src/components/features/Capacity/StakeForm.svelte

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import DropDownMenu from '../../atoms/DropDownMenu.svelte';
99
import { type Account, allAccountsStore } from '$lib/stores/accountsStore';
1010
import { Button } from '@frequency-chain/style-guide';
11+
import ButtonNoFill from '$atoms/ButtonNoFill.svelte';
1112
1213
interface Props {
1314
close: () => void;
@@ -66,14 +67,7 @@
6667
</div>
6768

6869
<div class="flex items-end justify-between">
69-
<Button
70-
type="primary"
71-
onclick={stake}
72-
disabled={isLoading}
73-
class="disabled:bg-gray3 disabled:text-white disabled:hover:shadow-none"
74-
>
75-
Stake</Button
76-
>
77-
<button class="btn-no-fill" onclick={close}>Cancel</button>
70+
<Button onclick={stake} disabled={isLoading}>Stake</Button>
71+
<ButtonNoFill onclick={close}>Cancel</ButtonNoFill>
7872
</div>
7973
</form>

src/components/features/HowToTransact/HowToTransact.svelte

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<script lang="ts">
2+
import { Button } from '@frequency-chain/style-guide';
3+
24
interface Props {
35
additionalStyles?: string;
46
}
57
68
let { additionalStyles = '' }: Props = $props();
79
</script>
810

9-
<div class={`column ${additionalStyles}`}>
11+
<div class={`column gap-f16 ${additionalStyles}`}>
1012
<p>
1113
To transact on Frequency as a Provider you will need Frequency utility tokens. On Frequency Testnet, you can get
1214
tokens from the Testnet Faucet sent to the Account Id that you want to use.
1315
</p>
1416

15-
<a href="https://faucet.testnet.frequency.xyz" target="_blank" class="btn-primary">Testnet Faucet</a>
17+
<Button href="https://faucet.testnet.frequency.xyz" target="_blank">Testnet Faucet</Button>
1618

1719
<ol class="ordered-list">
1820
<li>

src/components/features/LoginForm/LoginForm.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { user } from '$lib/stores/userStore';
55
import { Button } from '@frequency-chain/style-guide';
66
import SelectNetworkAndAccount from '../SelectNetworkAndAccount/SelectNetworkAndAccount.svelte';
7+
import ButtonNoFill from '$atoms/ButtonNoFill.svelte';
78
89
// Props
910
interface Props {
@@ -44,10 +45,10 @@
4445
/>
4546

4647
<div class="flex items-end justify-between">
47-
<Button type="primary" disabled={!canConnect} onclick={connect}>Connect to Account</Button>
48+
<Button disabled={!canConnect} onclick={connect}>Connect to Account</Button>
4849

4950
{#if onCancel}
50-
<button type="button" class="btn-no-fill hover:text-teal text-sm underline" onclick={onCancel}>Cancel</button>
51+
<ButtonNoFill onclick={onCancel}>Cancel</ButtonNoFill>
5152
{/if}
5253
</div>
5354
</form>

src/components/features/ProfileOverview/ActivityLogPreview.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ActivityLogPreviewItem from '../ActivityLogItem/ActivityLogItem.svelte';
33
import { activityLog } from '$lib/stores/activityLogStore';
44
import type { Activity } from '$lib/storeTypes';
5+
import { Button } from '@frequency-chain/style-guide';
56
67
let recentActivityItem: Activity = $derived($activityLog[0]);
78
</script>
@@ -12,9 +13,7 @@
1213

1314
{#if recentActivityItem}
1415
<ActivityLogPreviewItem activity={recentActivityItem} />
15-
<a href="/activity-log" class="mt-4 self-end">
16-
<button class="btn-primary">See all activity</button>
17-
</a>
16+
<Button href="/activity-log" class="mt-4 self-end">See all activity</Button>
1817
{:else}
1918
<div class="py-2 text-sm">No activity.</div>
2019
{/if}

src/components/features/Provider/AddAccountIdForm.svelte

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { dotApi } from '$lib/stores.js';
99
import { ApiPromise } from '@polkadot/api';
1010
import { preventDefault } from 'svelte/legacy';
11+
import ButtonNoFill from '$atoms/ButtonNoFill.svelte';
1112
1213
interface Props {
1314
onCancel: () => void;
@@ -53,12 +54,7 @@
5354
{/if}
5455

5556
<div class="flex items-end justify-between">
56-
<Button
57-
type="primary"
58-
onclick={addAccountId}
59-
disabled={isSubmitDisabled}
60-
class="disabled:bg-gray3 disabled:text-white disabled:hover:shadow-none">Add Account Id</Button
61-
>
62-
<button class="btn-no-fill hover:text-teal text-sm underline" onclick={preventDefault(onCancel)}>Cancel</button>
57+
<Button onclick={addAccountId} disabled={isSubmitDisabled}>Add Account Id</Button>
58+
<ButtonNoFill onclick={onCancel}>Cancel</ButtonNoFill>
6359
</div>
6460
</form>

src/components/features/Provider/Provider.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
</script>
4242

4343
<ListCard title="Provider" list={providerList} errorMessage={errMsg}>
44-
<Button size="sm" class="btn-primary" onclick={() => (isAddAccountIdOpen = true)}>Add Account Id</Button>
44+
<Button size="sm" onclick={() => (isAddAccountIdOpen = true)}>Add Account Id</Button>
4545
<AddAccountId isOpen={isAddAccountIdOpen} close={() => (isAddAccountIdOpen = false)} />
4646
</ListCard>

src/components/features/SelectNetworkAndAccount/SelectNetworkAndAccount.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import DropDownMenu from '$atoms/DropDownMenu.svelte';
1010
import { formatNetwork, formatAccount, isValidURL } from '$lib/utils';
1111
import { createApi } from '$lib/polkadotApi';
12+
import ButtonNoFill from '$atoms/ButtonNoFill.svelte';
1213
1314
interface Props {
1415
newUser: Account | null;
@@ -152,7 +153,7 @@
152153
{:else}
153154
<p class="my-f24 flex justify-between">
154155
<span class="text-teal">Connected to {selectedNetwork?.name || 'Custom'}</span>
155-
<button onclick={resetState} class="hover:text-teal cursor-pointer text-sm underline">Change networks</button>
156+
<ButtonNoFill onclick={resetState}>Change networks</ButtonNoFill>
156157
</p>
157158
{/if}
158159
{#if isCustomNetwork}

src/components/pages/ProviderLogin.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</a>
2222
<!-- TODO: remove div on button width fix -->
2323
<div>
24-
<Button type="primary" onclick={() => goto('/become-a-provider')}>Become a Provider</Button>
24+
<Button onclick={() => goto('/become-a-provider')}>Become a Provider</Button>
2525
</div>
2626
</div></BlockSection
2727
>

src/lib/stores/storable.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export function storable<T>(key: string, data?: T) {
88

99
if (storage) {
1010
const storageValue = storage.getItem(key);
11-
if (storageValue) {
12-
set(storageValue ? JSON.parse(storageValue) : data);
13-
}
11+
set(storageValue ? JSON.parse(storageValue) : data);
1412
}
1513

1614
function toJson(value: unknown) {

src/lib/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { formatBalance, hexToString, isFunction } from '@polkadot/util';
2+
import { clsx, type ClassValue } from 'clsx';
3+
import { twMerge } from 'tailwind-merge';
24
import type { Account } from './stores/accountsStore';
35
import { NetworkType, type NetworkInfo } from './stores/networksStore';
46

7+
export function cn(...inputs: ClassValue[]) {
8+
return twMerge(clsx(inputs));
9+
}
510
export async function sleep(ms: number): Promise<void> {
611
return new Promise((resolve) => setTimeout(resolve, ms));
712
}

src/style/app.css

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@config '../../tailwind.config.ts';
66

7-
/* */
7+
/* layout */
88
@utility title-h2 {
99
@apply font-title text-[50px] leading-[1] tracking-wider md:text-[60px] lg:text-[64px];
1010
}
@@ -15,7 +15,6 @@
1515
@apply font-title text-[18px] leading-[1] tracking-wider sm:text-[20px] md:text-[22px] lg:text-[26px];
1616
}
1717
@utility unordered-list {
18-
/* layout */
1918
@apply ml-6 list-disc text-wrap;
2019
}
2120
@utility ordered-list {
@@ -24,9 +23,11 @@
2423
@utility column {
2524
@apply flex flex-col;
2625
}
26+
27+
/* typography */
28+
/* headers */
29+
2730
@utility section-title {
28-
/* typography */
29-
/* headers */
3031
@apply text-xl font-bold;
3132
}
3233
@utility section-title-underlined {
@@ -35,8 +36,9 @@
3536
@utility label {
3637
@apply md:text-normal text-sm font-bold lg:tracking-wide;
3738
}
39+
40+
/* data */
3841
@utility data-value-sm {
39-
/* data */
4042
@apply font-data text-teal text-sm;
4143
}
4244
@utility data-value-md {
@@ -51,13 +53,14 @@
5153
@utility data-value-2xl {
5254
@apply font-data text-h3 text-teal;
5355
}
56+
57+
/* layout */
5458
@utility content-block {
55-
/* layout */
5659
@apply mb-f24 box-border rounded-md p-7;
5760
box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);
5861
}
62+
/* right side sizing */
5963
@utility main-section {
60-
/* right side sizing */
6164
@apply ml-f80 px-f16 md:ml-f128;
6265
a {
6366
@apply hover:text-teal underline transition duration-[0.3s];
@@ -67,10 +70,6 @@
6770
overflow-wrap: anywhere;
6871
}
6972

70-
@utility btn-no-fill {
71-
@apply hover:text-teal cursor-pointer text-sm underline;
72-
}
73-
7473
:root {
7574
--select-border: none;
7675
--select-arrow: var(--select-border);
@@ -81,10 +80,6 @@
8180
min-height: 100vh;
8281
}
8382

84-
button.btn-primary {
85-
@apply bg-teal p-f12 rounded-full text-center font-bold text-black transition-all hover:text-black hover:shadow-md;
86-
}
87-
8883
html {
8984
font-synthesis: none;
9085
text-rendering: optimizeLegibility;
@@ -97,6 +92,6 @@
9792
input,
9893
[type='text'],
9994
[type='number'] {
100-
@apply h-f40 text-normal border-gray3 hover:border-teal relative flex w-full max-w-[420px] cursor-pointer items-center justify-between rounded-md border bg-white p-2 px-3 py-2 align-middle text-[16px] overflow-ellipsis text-black outline-none disabled:cursor-not-allowed disabled:opacity-50;
95+
@apply h-f40 text-normal border-gray3 hover:border-teal relative flex w-full max-w-[420px] cursor-pointer items-center justify-between rounded-md border bg-white p-2 px-3 py-2 align-middle overflow-ellipsis text-black outline-none disabled:cursor-not-allowed disabled:opacity-50;
10196
}
10297
}

0 commit comments

Comments
 (0)