Skip to content

Commit f7413f9

Browse files
committed
dev(theme): enable to add css styles
1 parent ebd9a3e commit f7413f9

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

dev/App.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ const THEME_LIST: { label: string; key: Theme }[] = [
1818
{ label: "DARK", key: "dark" },
1919
];
2020

21+
const DEFAULT_CSS = `.gt-container {
22+
--gt-color-main: #059669;
23+
--gt-color-main-lighter: #10b981;
24+
}`;
25+
const GITALK_CUSTOM_CSS_KEY = "GITALK_CUSTOM_CSS";
26+
2127
const GITALK_BASE_OPTIONS: GitalkProps = import.meta.env.PROD
2228
? {
2329
clientID: "Ov23lizwQOGBomnxr5j1",
@@ -48,9 +54,12 @@ const I18N_LANGS = Object.keys(i18nMap) as Lang[];
4854
const App = () => {
4955
const [issuesPage, setIssuesPage] = useState<number>(1);
5056
const [issuesLoaded, setIssuesLoaded] = useState<boolean>(false);
57+
const [issueNumber, setIssueNumber] = useState<number>();
5158

5259
const [theme, setTheme] = useState<Theme>("light");
53-
const [issueNumber, setIssueNumber] = useState<number>();
60+
const [css, setCSS] = useState<string>(
61+
localStorage.getItem(GITALK_CUSTOM_CSS_KEY) ?? DEFAULT_CSS,
62+
);
5463

5564
const [options, setOptions] = useState<
5665
Omit<
@@ -168,6 +177,23 @@ const App = () => {
168177
location.href = url.toString();
169178
};
170179

180+
const onResetCSS = () => {
181+
document.getElementById(GITALK_CUSTOM_CSS_KEY)?.remove();
182+
183+
setCSS(DEFAULT_CSS);
184+
};
185+
186+
const onSetCSS = (cssString: string) => {
187+
document.getElementById(GITALK_CUSTOM_CSS_KEY)?.remove();
188+
189+
const style = document.createElement("style");
190+
style.id = GITALK_CUSTOM_CSS_KEY;
191+
style.textContent = cssString;
192+
document.head.appendChild(style);
193+
194+
localStorage.setItem(GITALK_CUSTOM_CSS_KEY, cssString);
195+
};
196+
171197
return (
172198
<div
173199
style={{
@@ -219,6 +245,32 @@ const App = () => {
219245
{themeLabel}
220246
</button>
221247
))}
248+
249+
<div style={{ width: "100%", marginTop: 12 }}>
250+
<textarea
251+
style={{
252+
width: "calc(100% - 16px)",
253+
minHeight: 100,
254+
resize: "vertical",
255+
padding: 8,
256+
}}
257+
placeholder="Custom your styles"
258+
value={css}
259+
onChange={(e) => setCSS(e.target.value)}
260+
/>
261+
<div style={{ width: "100%", marginTop: 6, textAlign: "end" }}>
262+
<button
263+
className="small"
264+
style={{ marginRight: 8 }}
265+
onClick={onResetCSS}
266+
>
267+
Reset
268+
</button>
269+
<button className="primary small" onClick={() => onSetCSS(css)}>
270+
Confirm
271+
</button>
272+
</div>
273+
</div>
222274
</div>
223275
</section>
224276

dev/app.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ body {
4848
box-shadow: 0 2px 4px 0 var(--secondary);
4949
}
5050

51+
&.small {
52+
padding: 4px 8px;
53+
font-size: 14px;
54+
border-radius: 4px;
55+
}
56+
5157
&.large {
5258
padding: 12px 24px;
5359
font-size: 18px;

0 commit comments

Comments
 (0)