fix: Settings styles

This commit is contained in:
Artemy 2023-04-04 17:15:25 +03:00
parent 2c07e71349
commit f3106daa4b
4 changed files with 97 additions and 92 deletions

View file

@ -1,5 +1,5 @@
import { CheckBox } from "./checkbox"; import { CheckBox } from "./checkbox";
import { inputStyle } from "./styles"; import { inputStyle, settingsAddInput } from "./styles";
function SettingsCheckBox({ label, title, className, settingName, onClick }) { function SettingsCheckBox({ label, title, className, settingName, onClick }) {
return ( return (
@ -27,12 +27,12 @@ function SettingsTextInput({
secret, secret,
}) { }) {
return ( return (
<div className="ml-2"> <div>
<label className="block mb-2 text-base font-medium text-gray-700 dark:text-white"> <label className="block mb-2 text-base font-medium text-gray-700 dark:text-white">
{label} {label}
</label> </label>
<input <input
className={`${inputStyle} m-2 ${className}`} className={`${inputStyle} ${settingsAddInput} m-2 ${className}`}
type={secret ? "password" : "text"} type={secret ? "password" : "text"}
placeholder={placeholder} placeholder={placeholder}
title={title} title={title}
@ -55,12 +55,12 @@ function SettingsSelectInput({
onChange, onChange,
}) { }) {
return ( return (
<div className="ml-2"> <div>
<label className="block mb-2 text-base font-medium text-gray-700 dark:text-white"> <label className="block mb-2 text-base font-medium text-gray-700 dark:text-white">
{label} {label}
</label> </label>
<select <select
className={`${inputStyle} m-2 ${className}`} className={`${inputStyle} ${settingsAddInput} m-2 ${className}`}
defaultValue={window.settings[settingName]} defaultValue={window.settings[settingName]}
onChange={(e) => { onChange={(e) => {
window.settings[settingName] = e.target.value; window.settings[settingName] = e.target.value;
@ -78,11 +78,14 @@ function SettingsSelectInput({
); );
} }
function SettingsPlaceholder({ text }) { function SettingsSection({ name, children }) {
return ( return (
<h1 className="text-center lg:text-left leading-tight text-xl font-semibold"> <div className="ml-0 lg:ml-6 mt-6 lg:mt-3">
{text} <h1 className="text-center lg:text-left leading-tight text-xl font-semibold">
</h1> {name}
</h1>
<div className="ml-0 lg:ml-6 mt-6 lg:mt-3">{children}</div>
</div>
); );
} }
@ -90,5 +93,5 @@ export {
SettingsCheckBox, SettingsCheckBox,
SettingsTextInput, SettingsTextInput,
SettingsSelectInput, SettingsSelectInput,
SettingsPlaceholder, SettingsSection,
}; };

View file

@ -1,4 +1,5 @@
let inputStyle = let inputStyle =
"w-full form-control block px-3 py-1.5 text-base font-normal text-gray-700 dark:text-white bg-white dark:bg-zinc-900 bg-clip-padding border border-solid border-gray-300 rounded-lg transition ease-in-out focus:border-blue-600 focus:outline-none"; "form-control block px-3 py-1.5 text-base font-normal text-gray-700 dark:text-white bg-white dark:bg-zinc-900 bg-clip-padding border border-solid border-gray-300 rounded-lg transition ease-in-out focus:border-blue-600 focus:outline-none";
let settingsAddInput = "w-full lg:w-1/4";
export { inputStyle }; export { inputStyle, settingsAddInput };

View file

@ -17,7 +17,7 @@ import remarkGfm from "remark-gfm";
import remarkMath from "remark-math"; import remarkMath from "remark-math";
import { import {
SettingsCheckBox, SettingsCheckBox,
SettingsPlaceholder, SettingsSection,
} from "../components/settingsInputs"; } from "../components/settingsInputs";
import { inputStyle } from "../components/styles"; import { inputStyle } from "../components/styles";
import { Complete } from "../components/openai"; import { Complete } from "../components/openai";
@ -136,18 +136,19 @@ function CreateNote() {
{settings.additionalFeatures && ( {settings.additionalFeatures && (
<div className="justify-self-start lg:justify-self-start"> <div className="justify-self-start lg:justify-self-start">
<SettingsPlaceholder text={locals.AdditionalFeatures} /> <SettingsSection name={locals.AdditionalFeatures}>
{!!settings.openAiKey && ( {!!settings.openAiKey && (
<ButtonWithIcon <ButtonWithIcon
icon={DocumentTextIcon} icon={DocumentTextIcon}
text={locals.AIComplete} text={locals.AIComplete}
className="m-1" className="m-1"
w="w-full" w="w-full"
onClick={() => { onClick={() => {
Complete(setText); Complete(setText);
}} }}
/> />
)} )}
</SettingsSection>
</div> </div>
)} )}
</div> </div>

View file

@ -2,91 +2,91 @@ import {
SettingsCheckBox, SettingsCheckBox,
SettingsTextInput, SettingsTextInput,
SettingsSelectInput, SettingsSelectInput,
SettingsPlaceholder, SettingsSection,
} from "../components/settingsInputs"; } from "../components/settingsInputs";
import { reRenderPage } from "../components/utils"; import { reRenderPage } from "../components/utils";
import Locales from "../localisation/main"; import Locales from "../localisation/main";
function Settings() { function Settings() {
return ( return (
<div className=""> <div>
<h1 className="text-center lg:text-left leading-tight text-2xl font-bold"> <h1 className="text-center lg:text-left leading-tight text-2xl font-bold">
{locals.Settings} {locals.Settings}
</h1> </h1>
<SettingsPlaceholder text={locals.User} /> <SettingsSection name={locals.User}>
<SettingsTextInput
placeholder={locals.Name}
label={locals.UserName}
settingName="userName"
/>
<SettingsTextInput <SettingsTextInput
placeholder={locals.Name} placeholder={locals.Url}
label={locals.UserName} label={locals.PhotoUrl}
settingName="userName" settingName="userPhoto"
/> />
<SettingsTextInput <SettingsTextInput
placeholder={locals.Url} placeholder={locals.Status}
label={locals.PhotoUrl} label={locals.UserStatus}
settingName="userPhoto" settingName="userStatus"
/> />
</SettingsSection>
<SettingsTextInput <SettingsSection name={locals.Notes}>
placeholder={locals.Status} <SettingsCheckBox
label={locals.UserStatus} label={locals.EditPreview}
settingName="userStatus" title={locals.EditPreviewWarn}
/> settingName="editPreview"
/>
<SettingsPlaceholder text={locals.Notes} /> <SettingsCheckBox
label={locals.PublicNote}
title={locals.PublicNoteTitle}
settingName="publicNote"
/>
<SettingsCheckBox <SettingsCheckBox
label={locals.EditPreview} label={locals.AdditionalFeatures}
title={locals.EditPreviewWarn} settingName="additionalFeatures"
settingName="editPreview" />
/> </SettingsSection>
<SettingsCheckBox <SettingsSection name={locals.Interface}>
label={locals.PublicNote} <SettingsSelectInput
title={locals.PublicNoteTitle} label={locals.Language}
settingName="publicNote" settingName="language"
/> options={[
{
value: "ru",
label: "Русский",
},
{
value: "en",
label: "English (US)",
},
]}
onChange={(e) => {
window.locals =
Locales[window.settings.language] ||
Locales[navigator.language] ||
Locales[navigator.userLanguage] ||
Locales.en;
<SettingsCheckBox reRenderPage();
label={locals.AdditionalFeatures} }}
settingName="additionalFeatures" />
/> </SettingsSection>
<SettingsPlaceholder text={locals.Interface} /> <SettingsSection name={locals.ThirdPartyApi}>
<SettingsTextInput
<SettingsSelectInput placeholder={locals.Key}
label={locals.Language} label={locals.OpenAiKey}
settingName="language" settingName="openAiKey"
options={[ secret
{ />
value: "ru", </SettingsSection>
label: "Русский",
},
{
value: "en",
label: "English (US)",
},
]}
onChange={(e) => {
window.locals =
Locales[window.settings.language] ||
Locales[navigator.language] ||
Locales[navigator.userLanguage] ||
Locales.en;
reRenderPage();
}}
/>
<SettingsPlaceholder text={locals.ThirdPartyApi} />
<SettingsTextInput
placeholder={locals.Key}
label={locals.OpenAiKey}
settingName="openAiKey"
secret
/>
</div> </div>
); );
} }