Skip to content

Commit

Permalink
refactor: adjusting field methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasfreitas-dev committed Jul 31, 2024
1 parent 4095cbc commit de39c80
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
9 changes: 4 additions & 5 deletions src/components/Dropdown/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

.dropdown {
width: 100%;
height: 100%;

font-family: fonts.$primaryFont;
font-size: 1.4rem;
font-weight: fonts.$semiBold;

color: colors.$gray800;
font-size: 1.4rem;
font-weight: fonts.$semiBold;

position: relative;

Expand Down Expand Up @@ -59,12 +58,12 @@

padding: 1.8rem 1.6rem;

border: 1px solid colors.$gray200;

box-sizing: border-box;

background-color: colors.$white;

border: 1px solid colors.$gray200;

border-radius: 1.4rem;

.dropdown__icon {
Expand Down
14 changes: 7 additions & 7 deletions src/components/RegisterForm/components/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const html = `

export default function Field({ label = '', error = '', content } = {}) {
Component.call(this, { html, events });
this.content = null;
this.setLabel(label);
this.setError(error);
this.setContent(content);
Expand All @@ -45,12 +44,14 @@ Field.prototype = Object.assign(Field.prototype, Component.prototype, {
},

showError(error) {
this.selected.get('field-error').classList.add('show-error');
this.selected.get('field-error').classList.add('field__error--show-error');
this.emit('error:visible', error);
},

resError(error) {
this.selected.get('field-error').classList.remove('show-error');
resolveError(error) {
this.selected
.get('field-error')
.classList.remove('field__error--show-error');
this.emit('error:resolved', error);
},

Expand All @@ -59,9 +60,8 @@ Field.prototype = Object.assign(Field.prototype, Component.prototype, {
},

setContent(content) {
if (content?.mount == null) {
return;
}
if (content?.mount === null)
throw new Error('Esse método espera receber um componente');

this.content = content;
this.content.mount(this.selected.get('field-input'));
Expand Down
6 changes: 3 additions & 3 deletions src/components/RegisterForm/components/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
&__label {
display: block;

color: colors.$gray800;

font-size: fonts.$xs;
font-weight: fonts.$medium;

color: colors.$gray800;

padding: 0 0 0.5rem 0.5rem;
}

Expand All @@ -24,7 +24,7 @@

margin: 0.8rem 0 0 0.5rem;

&.show-error {
&--show-error {
display: block;
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/components/RegisterForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './index.scss';
const events = ['register'];

const html = `
<div data-select="component" class="register-form">
<div class="register-form">
<h1 class="register-form__title">Crie sua petconta</h1>
<div class="register-form__socials">
<button class="register-form__social">
Expand Down Expand Up @@ -229,35 +229,35 @@ export default function RegisterForm() {
}

if (nameValid) {
name.resError();
name.resolveError();
}

if (surnameValid) {
surname.resError();
surname.resolveError();
}

if (birthValid) {
birth.resError();
birth.resolveError();
}

if (localValid) {
local.resError();
local.resolveError();
}

if (emailValid) {
email.resError();
email.resolveError();
}

if (phoneValid) {
phone.resError();
phone.resolveError();
}

if (passwordValid) {
password.resError();
password.resolveError();
}

if (repeatPasswordValid) {
repeatPassword.resError();
repeatPassword.resolveError();
}

if (
Expand Down
4 changes: 1 addition & 3 deletions src/components/RegisterForm/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
@use '~styles/breakpoints.scss' as breakpoints;

.register-form {
width: 80%;
height: 100%;
width: 100%;

display: flex;
flex-direction: column;
Expand All @@ -14,7 +13,6 @@
font-family: fonts.$primaryFont;

margin: 0 auto;
padding: 0 2rem;

&__title {
color: colors.$gray800;
Expand Down
2 changes: 1 addition & 1 deletion src/styles/colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $success200: rgb(49, 138, 94);
// error
$error100: rgb(179, 38, 30);

// white
// White

$white: rgb(255, 255, 255);

Expand Down

0 comments on commit de39c80

Please sign in to comment.