1
0
mirror of https://github.com/XFox111/PasswordGeneratorExtension.git synced 2026-04-22 08:08:01 +03:00
Files
PasswordGeneratorExtension/entrypoints/options/SettingsSection.tsx
T
xfox111 a4de3139bf Minor 5.1.0 (#560)
* Force no-wrap for special characters tooltip (resolves #551) (#555)

* Increase width of password count field in advanced generator (resolves #548) (#554)

* Added password length limit in advanced generator (#552)

* Added password length limit in advanced generator (resolves #547)

* Add radix to parseInt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove unnecessary callback dependency

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* npm audit fix (#556)

* Added length slider range limits (#557)

* Added length slider range limits (resolves #546)

* Fix validateMaxLimit logic

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Added password length update on input field blur (resolves #549) (#559)

* Separator option for advanced password generator (#558)

* Added separator option for advanced password generator (resolves #545)

* Fix typos

* Fixed merge typo

* Update package.json

* Bump @fluentui/react-components from 9.64.0 to 9.66.5 (#561)

Bumps [@fluentui/react-components](https://github.com/microsoft/fluentui) from 9.64.0 to 9.66.5.
- [Release notes](https://github.com/microsoft/fluentui/releases)
- [Changelog](https://github.com/microsoft/fluentui/blob/master/azure-pipelines.release.yml)
- [Commits](https://github.com/microsoft/fluentui/compare/@fluentui/react-components_v9.64.0...@fluentui/react-components_v9.66.5)

---
updated-dependencies:
- dependency-name: "@fluentui/react-components"
  dependency-version: 9.66.5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @typescript-eslint/parser from 8.33.1 to 8.35.1 (#562)

Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 8.33.1 to 8.35.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.35.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-version: 8.35.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @eslint/js from 9.28.0 to 9.30.0 (#564)

Bumps [@eslint/js](https://github.com/eslint/eslint/tree/HEAD/packages/js) from 9.28.0 to 9.30.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/commits/v9.30.0/packages/js)

---
updated-dependencies:
- dependency-name: "@eslint/js"
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint from 9.28.0 to 9.30.0 (#566)

Bumps [eslint](https://github.com/eslint/eslint) from 9.28.0 to 9.30.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v9.28.0...v9.30.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-version: 9.30.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @typescript-eslint/eslint-plugin from 8.33.1 to 8.35.1 (#563)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 8.33.1 to 8.35.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.35.1/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-version: 8.35.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @fluentui/react-icons from 2.0.302 to 2.0.305 (#565)

Bumps [@fluentui/react-icons](https://github.com/microsoft/fluentui-system-icons) from 2.0.302 to 2.0.305.
- [Changelog](https://github.com/microsoft/fluentui-system-icons/blob/main/fluentui-android-system-icons-release.yml)
- [Commits](https://github.com/microsoft/fluentui-system-icons/commits)

---
updated-dependencies:
- dependency-name: "@fluentui/react-icons"
  dependency-version: 2.0.305
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Moved default password lengths to constants (#553)

* Added radix 10 for parseInt (#553)

* Removed ts-expect-error microsoft/fluentui#27090

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-01 11:25:32 +03:00

158 lines
5.7 KiB
TypeScript

import { CharacterHints } from "@/utils/generators/generatePassword";
import { ExtensionOptions, GeneratorOptions, useStorage } from "@/utils/storage";
import * as fui from "@fluentui/react-components";
import { ArrowUndoRegular } from "@fluentui/react-icons";
import { ReactElement } from "react";
import infoLabel from "../../utils/infoLabel";
import { useStyles } from "./SettingsSection.styles";
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH } from "@/utils/constants";
export default function SettingsSection(): ReactElement
{
const { extOptions, generatorOptions, updateStorage } = useStorage();
const cls = useStyles();
const resetRange = useCallback(() =>
{
updateStorage({
MinLength: defaultOptions.extension.MinLength,
MaxLength: defaultOptions.extension.MaxLength
});
}, []);
const setOption = (option: keyof (GeneratorOptions & ExtensionOptions)) =>
(_: unknown, args: fui.CheckboxOnChangeData) =>
updateStorage({ [option]: args.checked });
const updateNumberField = (key: keyof (ExtensionOptions & GeneratorOptions), defaultValue: number) =>
(_: unknown, e: fui.InputOnChangeData): void =>
{
if (e.value.length >= 1)
{
const value = parseInt(e.value, 10);
if (!isNaN(value) && value >= 0)
updateStorage({ [key]: value });
}
else
updateStorage({ [key]: defaultValue });
};
const validateMinLimit = () =>
{
if (extOptions.MinLength < MIN_PASSWORD_LENGTH)
updateStorage({ MinLength: MIN_PASSWORD_LENGTH });
else if (extOptions.MinLength > MAX_PASSWORD_LENGTH - 1)
updateStorage({ MinLength: MAX_PASSWORD_LENGTH - 1, MaxLength: MAX_PASSWORD_LENGTH });
else if (extOptions.MinLength >= extOptions.MaxLength)
updateStorage({ MaxLength: extOptions.MinLength + 1 });
};
const validateMaxLimit = () =>
{
if (extOptions.MaxLength > MAX_PASSWORD_LENGTH)
updateStorage({ MaxLength: MAX_PASSWORD_LENGTH });
else if (extOptions.MaxLength < MIN_PASSWORD_LENGTH + 1)
updateStorage({ MinLength: MIN_PASSWORD_LENGTH, MaxLength: MIN_PASSWORD_LENGTH + 1 });
else if (extOptions.MaxLength <= extOptions.MinLength)
updateStorage({ MinLength: extOptions.MaxLength - 1 });
};
const validateLength = () =>
{
updateStorage({ Length: Math.max(Math.min(generatorOptions.Length, extOptions.MaxLength), extOptions.MinLength) });
};
return (
<section className={ cls.root }>
<fui.Field label={ i18n.t("settings.length.title") } hint={ i18n.t("settings.length.hint") }>
<fui.Input
value={ generatorOptions.Length.toString() }
onBlur={ validateLength }
onChange={ updateNumberField("Length", 0) } />
</fui.Field>
<fui.Field label={ i18n.t("settings.quick_range") }>
<div className={ cls.rangeContainer }>
<fui.Input
input={ { className: cls.rangeInput } }
value={ extOptions.MinLength.toString() }
onBlur={ validateMinLimit }
onChange={ updateNumberField("MinLength", defaultOptions.extension.MinLength) } />
<fui.Divider />
<fui.Input
input={ { className: cls.rangeInput } }
value={ extOptions.MaxLength.toString() }
onBlur={ validateMaxLimit }
onChange={ updateNumberField("MaxLength", defaultOptions.extension.MaxLength) } />
<fui.Tooltip relationship="label" content={ i18n.t("common.actions.reset") }>
<fui.Button
appearance="subtle" icon={ <ArrowUndoRegular /> }
onClick={ resetRange } />
</fui.Tooltip>
</div>
</fui.Field>
<fui.Divider className={ cls.divider } />
<fui.Text>{ i18n.t("common.sections.include") }</fui.Text>
<div className={ cls.checkboxContainer }>
<fui.Checkbox label={ i18n.t("common.characters.uppercase") }
checked={ generatorOptions.Uppercase }
onChange={ setOption("Uppercase") } />
<fui.Checkbox
label={ i18n.t("common.characters.lowercase") }
checked={ generatorOptions.Lowercase }
onChange={ setOption("Lowercase") } />
<fui.Checkbox
label={ i18n.t("common.characters.numeric") }
checked={ generatorOptions.Numeric }
onChange={ setOption("Numeric") } />
<fui.Checkbox
label={ infoLabel(i18n.t("common.characters.special"), CharacterHints.special, true) }
checked={ generatorOptions.Special }
onChange={ setOption("Special") } />
<div>
<fui.Checkbox checked={ generatorOptions.Custom } onChange={ setOption("Custom") } />
<fui.Input size="small" placeholder={ i18n.t("common.characters.custom") }
value={ generatorOptions.IncludeCustomSet }
onChange={ (_, e) => updateStorage({ IncludeCustomSet: e.value }) } />
</div>
</div>
<fui.Text>{ i18n.t("common.sections.exclude") }</fui.Text>
<div className={ cls.checkboxContainer }>
<fui.Checkbox
label={ infoLabel(i18n.t("common.characters.similar"), CharacterHints.similar) }
checked={ generatorOptions.ExcludeSimilar }
onChange={ setOption("ExcludeSimilar") } />
<fui.Checkbox
label={ infoLabel(i18n.t("common.characters.ambiguous"), CharacterHints.ambiguous) }
disabled={ !generatorOptions.Special }
checked={ generatorOptions.ExcludeAmbiguous }
onChange={ setOption("ExcludeAmbiguous") } />
<fui.Checkbox
label={ infoLabel(i18n.t("common.characters.repeating.label"), i18n.t("common.characters.repeating.hint")) }
checked={ generatorOptions.ExcludeRepeating }
onChange={ setOption("ExcludeRepeating") } />
<div>
<fui.Checkbox checked={ generatorOptions.ExcludeCustom } onChange={ setOption("ExcludeCustom") } />
<fui.Input size="small" placeholder={ i18n.t("common.characters.custom") }
value={ generatorOptions.ExcludeCustomSet }
onChange={ (_, e) => updateStorage({ ExcludeCustomSet: e.value }) } />
</div>
</div>
</section>
);
};
const defaultOptions =
{
generator: new GeneratorOptions(),
extension: new ExtensionOptions()
};