refactor: better initial extension UI

This commit is contained in:
Abhijith Vijayan [FLUXON] 2026-01-03 19:26:02 +05:30
parent b96c1969df
commit bdf0ca1806
6 changed files with 230 additions and 102 deletions

View File

@ -2,6 +2,12 @@ import * as React from 'react';
import {useEffect, useState} from 'react'; import {useEffect, useState} from 'react';
import {getStorage, setStorage} from '../utils/storage'; import {getStorage, setStorage} from '../utils/storage';
const GitHubIcon: React.FC = () => (
<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
</svg>
);
const Options: React.FC = () => { const Options: React.FC = () => {
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
const [enableLogging, setEnableLogging] = useState(false); const [enableLogging, setEnableLogging] = useState(false);
@ -77,6 +83,18 @@ const Options: React.FC = () => {
{saved && <span className="options__status">Settings saved</span>} {saved && <span className="options__status">Settings saved</span>}
</div> </div>
</form> </form>
<footer className="options__footer">
<a
href="https://github.com/abhijithvijayan/web-extension-starter"
target="_blank"
rel="noopener noreferrer"
className="options__github-link"
>
<GitHubIcon />
<span>View on GitHub</span>
</a>
</footer>
</div> </div>
); );
}; };

View File

@ -4,38 +4,45 @@
body { body {
color: variables.$black; color: variables.$black;
background-color: variables.$greyWhite; background: linear-gradient(180deg, variables.$greyWhite 0%, #eef2f7 100%);
min-height: 100vh; min-height: 100vh;
display: flex; display: flex;
justify-content: center; justify-content: center;
padding: 40px 20px; padding: 50px 20px;
font-family: variables.$fontFamily;
} }
.options { .options {
width: 100%; width: 100%;
max-width: 500px; max-width: 480px;
&__header { &__header {
margin-bottom: 30px; margin-bottom: 32px;
text-align: center; text-align: center;
h1 { h1 {
font-size: 24px; font-size: 26px;
font-weight: 700; font-weight: variables.$bold;
margin-bottom: 8px; margin-bottom: 10px;
background: linear-gradient(135deg, variables.$primary 0%, #8b5cf6 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
} }
p { p {
color: variables.$skyBlue; color: variables.$skyBlue;
font-size: 14px; font-size: 14px;
font-weight: variables.$medium;
} }
} }
&__card { &__card {
background: white; background: variables.$cardBg;
border-radius: 12px; border-radius: variables.$radiusLg;
padding: 24px; padding: 28px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); box-shadow: variables.$shadowLg;
border: 1px solid variables.$border;
} }
&__section { &__section {
@ -48,110 +55,165 @@ body {
&__label { &__label {
display: block; display: block;
font-size: 14px; font-size: 13px;
font-weight: 600; font-weight: variables.$semibold;
margin-bottom: 8px; margin-bottom: 10px;
color: variables.$black; color: variables.$black;
text-transform: uppercase;
letter-spacing: 0.5px;
} }
&__input { &__input {
width: 100%; width: 100%;
padding: 12px 14px; padding: 14px 16px;
font-size: 14px; font-size: 15px;
background-color: white; background-color: variables.$white;
color: variables.$black; color: variables.$black;
border: 1px solid #e0e0e0; border: 2px solid variables.$border;
border-radius: 8px; border-radius: variables.$radiusMd;
transition: border-color 0.2s, box-shadow 0.2s; transition: all 0.2s ease;
box-sizing: border-box; box-sizing: border-box;
&:hover {
border-color: #cbd5e1;
}
&:focus { &:focus {
outline: none; outline: none;
border-color: #4a90d9; border-color: variables.$primary;
box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.15);
} }
&::placeholder { &::placeholder {
color: #a0a0a0; color: #94a3b8;
} }
} }
&__checkbox-wrapper { &__checkbox-wrapper {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;
gap: 12px; gap: 14px;
padding: 14px; padding: 16px;
background: #f8f9fa; background: variables.$greyWhite;
border-radius: 8px; border-radius: variables.$radiusMd;
cursor: pointer; cursor: pointer;
transition: background 0.2s; transition: all 0.2s ease;
border: 2px solid transparent;
&:hover { &:hover {
background: #f0f1f3; background: #eef2f7;
border-color: variables.$border;
} }
} }
&__checkbox { &__checkbox {
width: 18px; width: 20px;
height: 18px; height: 20px;
margin-top: 2px; margin-top: 2px;
cursor: pointer; cursor: pointer;
accent-color: #4a90d9; accent-color: variables.$primary;
} }
&__checkbox-text { &__checkbox-text {
font-size: 14px; font-size: 14px;
line-height: 1.5; line-height: 1.5;
color: #444; color: variables.$skyBlue;
font-weight: variables.$medium;
} }
&__actions { &__actions {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 16px; gap: 16px;
margin-top: 24px; margin-top: 28px;
padding-top: 24px; padding-top: 24px;
border-top: 1px solid #eee; border-top: 1px solid variables.$border;
} }
&__button { &__button {
padding: 12px 24px; padding: 14px 28px;
font-size: 14px; font-size: 14px;
font-weight: 600; font-weight: variables.$semibold;
border: none; border: none;
border-radius: 8px; border-radius: variables.$radiusMd;
cursor: pointer; cursor: pointer;
transition: opacity 0.2s, transform 0.1s; transition: all 0.2s ease;
&:hover { &:hover {
opacity: 0.9; transform: translateY(-2px);
box-shadow: variables.$shadowMd;
} }
&:active { &:active {
transform: scale(0.98); transform: translateY(0);
} }
&--primary { &--primary {
background: #4a90d9; background: linear-gradient(135deg, variables.$primary 0%, variables.$primaryDark 100%);
color: white; color: variables.$white;
} }
} }
&__status { &__status {
font-size: 14px; font-size: 14px;
color: #2d8a2d; color: variables.$success;
font-weight: 500; font-weight: variables.$semibold;
display: flex; display: flex;
align-items: center; align-items: center;
gap: 6px; gap: 8px;
&::before { &::before {
content: ""; content: "";
display: inline-block; display: inline-block;
width: 8px; width: 8px;
height: 8px; height: 8px;
background: #2d8a2d; background: variables.$success;
border-radius: 50%; border-radius: 50%;
animation: pulse 1s ease-in-out;
}
}
&__footer {
margin-top: 24px;
text-align: center;
}
&__github-link {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 10px 20px;
font-size: 14px;
font-weight: variables.$medium;
color: variables.$skyBlue;
background: variables.$cardBg;
border: 1px solid variables.$border;
border-radius: variables.$radiusMd;
transition: all 0.2s ease;
&:hover {
color: variables.$black;
border-color: #cbd5e1;
box-shadow: variables.$shadowSm;
transform: translateY(-1px);
}
svg {
flex-shrink: 0;
} }
} }
} }
@keyframes pulse {
0% {
transform: scale(0);
opacity: 0;
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
opacity: 1;
}
}

View File

@ -1,6 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import {useEffect, useState} from 'react'; import {useEffect, useState} from 'react';
import browser, {Tabs} from 'webextension-polyfill'; import browser, {Tabs} from 'webextension-polyfill';
import {getStorage} from '../utils/storage';
function openWebPage(url: string): Promise<Tabs.Tab> { function openWebPage(url: string): Promise<Tabs.Tab> {
return browser.tabs.create({url}); return browser.tabs.create({url});
@ -14,6 +15,7 @@ interface TabInfo {
const Popup: React.FC = () => { const Popup: React.FC = () => {
const [tabInfo, setTabInfo] = useState<TabInfo | null>(null); const [tabInfo, setTabInfo] = useState<TabInfo | null>(null);
const [username, setUsername] = useState<string>('');
useEffect(() => { useEffect(() => {
browser.tabs.query({active: true, currentWindow: true}).then((tabs) => { browser.tabs.query({active: true, currentWindow: true}).then((tabs) => {
@ -26,6 +28,10 @@ const Popup: React.FC = () => {
}); });
} }
}); });
getStorage(['username']).then(({username: storedUsername}) => {
setUsername(storedUsername);
});
}, []); }, []);
const handleReloadTab = async (): Promise<void> => { const handleReloadTab = async (): Promise<void> => {
@ -44,6 +50,7 @@ const Popup: React.FC = () => {
<section className="popup"> <section className="popup">
<header className="popup__header"> <header className="popup__header">
<h1 className="popup__title">Web Extension Starter</h1> <h1 className="popup__title">Web Extension Starter</h1>
{username && <p className="popup__greeting">Hello, {username}!</p>}
</header> </header>
{tabInfo && ( {tabInfo && (

View File

@ -4,8 +4,9 @@
body { body {
color: variables.$black; color: variables.$black;
background-color: variables.$greyWhite; background: linear-gradient(180deg, variables.$greyWhite 0%, #eef2f7 100%);
width: 100%; width: 100%;
font-family: variables.$fontFamily;
} }
.popup { .popup {
@ -14,68 +15,81 @@ body {
&__header { &__header {
text-align: center; text-align: center;
margin-bottom: 16px; margin-bottom: 20px;
padding-bottom: 16px; padding-bottom: 16px;
border-bottom: 1px solid #eee; border-bottom: 1px solid variables.$border;
} }
&__title { &__title {
font-size: 16px; font-size: 18px;
font-weight: 700; font-weight: variables.$bold;
letter-spacing: 0.5px; letter-spacing: -0.3px;
color: variables.$black; color: variables.$black;
background: linear-gradient(135deg, variables.$primary 0%, #8b5cf6 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
&__greeting {
font-size: 13px;
color: variables.$skyBlue;
margin-top: 6px;
font-weight: variables.$medium;
} }
&__card { &__card {
background: white; background: variables.$cardBg;
border-radius: 10px; border-radius: variables.$radiusLg;
padding: 16px; padding: 18px;
margin-bottom: 12px; margin-bottom: 14px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); box-shadow: variables.$shadowMd;
border: 1px solid variables.$border;
} }
&__card-header { &__card-header {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
margin-bottom: 12px; margin-bottom: 14px;
} }
&__card-title { &__card-title {
font-size: 12px; font-size: 11px;
font-weight: 600; font-weight: variables.$bold;
text-transform: uppercase; text-transform: uppercase;
letter-spacing: 0.5px; letter-spacing: 0.8px;
color: variables.$skyBlue; color: variables.$skyBlue;
} }
&__tab-content { &__tab-content {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 12px; gap: 14px;
margin-bottom: 14px; margin-bottom: 16px;
} }
&__favicon { &__favicon {
width: 40px; width: 44px;
height: 40px; height: 44px;
border-radius: 8px; border-radius: variables.$radiusMd;
flex-shrink: 0; flex-shrink: 0;
background: #f0f0f0; background: variables.$greyWhite;
object-fit: cover; object-fit: cover;
border: 1px solid variables.$border;
} }
&__favicon-placeholder { &__favicon-placeholder {
width: 40px; width: 44px;
height: 40px; height: 44px;
border-radius: 8px; border-radius: variables.$radiusMd;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); background: linear-gradient(135deg, variables.$primary 0%, #8b5cf6 100%);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
color: white; color: variables.$white;
font-size: 18px; font-size: 18px;
font-weight: 700; font-weight: variables.$bold;
flex-shrink: 0; flex-shrink: 0;
} }
@ -86,12 +100,13 @@ body {
&__tab-title { &__tab-title {
font-size: 14px; font-size: 14px;
font-weight: 600; font-weight: variables.$semibold;
color: variables.$black; color: variables.$black;
margin-bottom: 4px; margin-bottom: 4px;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
line-height: 1.3;
} }
&__tab-url { &__tab-url {
@ -104,71 +119,80 @@ body {
&__btn { &__btn {
width: 100%; width: 100%;
padding: 10px 14px; padding: 11px 16px;
font-size: 13px; font-size: 13px;
font-weight: 500; font-weight: variables.$semibold;
border: none; border: none;
border-radius: 8px; border-radius: variables.$radiusMd;
cursor: pointer; cursor: pointer;
transition: all 0.15s ease; transition: all 0.2s ease;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 8px;
&:hover { &:hover {
transform: translateY(-1px); transform: translateY(-2px);
box-shadow: variables.$shadowMd;
} }
&:active { &:active {
transform: translateY(0); transform: translateY(0);
} }
&--primary {
background: linear-gradient(135deg, variables.$primary 0%, variables.$primaryDark 100%);
color: variables.$white;
}
&--secondary { &--secondary {
background: #f0f1f3; background: variables.$greyWhite;
color: #444; color: variables.$black;
border: 1px solid variables.$border;
&:hover { &:hover {
background: #e4e5e7; background: #eef2f7;
} }
} }
} }
&__footer { &__footer {
display: flex; display: flex;
gap: 8px; gap: 10px;
margin-top: 4px;
} }
&__footer-btn { &__footer-btn {
flex: 1; flex: 1;
padding: 12px; padding: 12px 10px;
font-size: 13px; font-size: 12px;
font-weight: 600; font-weight: variables.$semibold;
border: none; border: none;
border-radius: 8px; border-radius: variables.$radiusMd;
cursor: pointer; cursor: pointer;
transition: all 0.15s ease; transition: all 0.2s ease;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 6px;
&:hover { &:hover {
transform: translateY(-1px); transform: translateY(-2px);
box-shadow: variables.$shadowMd;
} }
&--settings { &--settings {
background: #4a90d9; background: linear-gradient(135deg, variables.$primary 0%, #8b5cf6 100%);
color: white; color: variables.$white;
} }
&--github { &--github {
background: #24292e; background: linear-gradient(135deg, #24292e 0%, #1a1a1a 100%);
color: white; color: variables.$white;
} }
&--support { &--support {
background: #ff813f; background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
color: white; color: variables.$white;
} }
} }
} }

View File

@ -1 +1 @@
@import url("https://fonts.googleapis.com/css?family=Nunito:400,600"); @import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

View File

@ -1,10 +1,17 @@
// colors // colors
$black: #0d0d0d; $black: #1a1a2e;
$greyWhite: #f3f3f3; $greyWhite: #f8f9fc;
$skyBlue: #8892b0; $skyBlue: #64748b;
$primary: #6366f1;
$primaryDark: #4f46e5;
$success: #10b981;
$danger: #ef4444;
$white: #ffffff;
$border: #e2e8f0;
$cardBg: #ffffff;
// fonts // fonts
$nunito: "Nunito", sans-serif; $fontFamily: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
// font weights // font weights
$thin: 100; $thin: 100;
@ -17,6 +24,16 @@ $bold: 700;
$exbold: 800; $exbold: 800;
$exblack: 900; $exblack: 900;
// border radius
$radiusSm: 6px;
$radiusMd: 10px;
$radiusLg: 14px;
// shadows
$shadowSm: 0 1px 2px rgba(0, 0, 0, 0.05);
$shadowMd: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
$shadowLg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
// other variables // other variables
.d-none { .d-none {
display: none !important; display: none !important;