Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Button component #3

Merged
merged 16 commits into from
Jun 17, 2024
Merged

Conversation

chessurisme
Copy link
Member

@chessurisme chessurisme commented May 9, 2024

❓ What type of PR is this?

  • Refactor ♻️
  • Feature ✨
  • Bug Fix 🛠️
  • Optimization 🚀
  • Documentation Update 📄
  • CI/CD 🤖

💬 Description

This PR includes a Button component class with methods of creation and removal.

This is responsible for creating a button throughout the DOM.

🎟️ Related Tickets & Documents

🃏 Added/updated tests?

We encourage you to keep the code coverage percentage at 90% and above.

  • Yes
  • No, because this is not necessary.
  • No, and this is why: I haven't write it yet.
  • I need help with writing tests

📚 Resources for Reviewers

🌿 What branch would you like to merge this into?

feature/components

📷 [optional] What gif best describes this PR or how it makes you feel?

@chessurisme chessurisme added the ✨ enhancement New feature or request label May 9, 2024
@chessurisme chessurisme added this to the Quiz Manager 1.0 milestone May 9, 2024
@chessurisme chessurisme self-assigned this May 9, 2024
Implement the Button component to handle button creation and removal
based on the provided configuration. The button class consists of a
constructor method that initializes the configuration, a create method
to create buttons, and a remove method to remove buttons. This
implementation ensures that the provided configuration is verified
before creating or removing buttons.
This function creates a button element based on the provided
configuration object. It checks if the configuration is verified before
creating the button. If the configuration is not verified, the function
returns undefined. The button type determines the style of the button:
rounded-square, slab, or transparent.
This function creates a container element for a button, allowing the
inclusion of an icon, text, and various attributes such as ID, class
name, and event listeners. It uses helper functions from the utilities
module to set attributes and events for the container element.
This function removes a button element from the DOM based on the
provided configuration. It utilizes strict mode for improved code
quality and reliability.
Ensure early return in the if statement when events are not present in
the configuration. This adjustment improves code clarity and adheres to
the expected behavior. Additionally, relocate the error message handling
to the `button-create-container` file for better organization within the
codebase.
Due to changes in the configuration verification utility, parameters
needed to be updated in this.config at condition. Added this.name to
make the parameters more readable and ensure proper initialization.
The `button-create` file had a helper function `button-create-container`.
Merged them into one file for better file organization within the
components folder. This change helps in tracking related functions more
effectively.
Updated `button-create` by adding the 'button' parameter due to changes
in the configuration verifier. This ensures the function operates with
the correct parameters.
Set 'text' to let instead of const to accommodate 'rounded-square' type
of button, which forces such buttons to have no 'text'. This change
ensures that the 'text' can be modified in the switch statement even if
explicitly included in the config properties. Keeping other properties
as const prevents unintended changes, maintaining stability.
Ensure the icon is wrapped in an `i` element instead of a `div` for
proper icon display and alignment according to standard practices.
Introduce tests to validate the functionality of the Button component
methods. These tests provide assurance regarding the reliability and
correctness of the methods implemented within the component.
Updated import paths in component files to use module resolution aliases
defined in jsconfig.json. This change improves code readability and
maintainability by replacing relative paths with aliases.
Fixes the bug of not setting events on a button because the button is
not yet created or appended to the DOM. Event setting relies on the
element's ID in the DOM. Separated event setting into another method to
address this issue. Additionally, return `this` in methods where
chaining is necessary.
Combine multiple files into a single file to reduce unnecessary module
creation. This change simplifies navigation and improves codebase
organization.
Combine multiple test files into a single test file to reduce
unnecessary module tests. This change simplifies navigation and improves
codebase organization.
Adjusted code formatting to adhere to a maximum print width of 100characters, improving readability and consistency across the codebase.
@chessurisme
Copy link
Member Author

Since the files have been merged into one, most of the bugs have been fixed, including:

  • setting events when the button is created.
  • getting the button node ready for appending.
  • removing button events.

The merged test ensures everything is working well.

Alas, no more getting lost trying to find multiple files. 😁

@chessurisme chessurisme merged commit 615bf56 into feature/components Jun 17, 2024
1 check passed
@chessurisme chessurisme deleted the feature/button branch June 17, 2024 03:11
chessurisme added a commit that referenced this pull request Jun 18, 2024
* feat: implement Button component

Implement the Button component to handle button creation and removal
based on the provided configuration. The button class consists of a
constructor method that initializes the configuration, a create method
to create buttons, and a remove method to remove buttons. This
implementation ensures that the provided configuration is verified
before creating or removing buttons.

* feat: implement button creation function

This function creates a button element based on the provided
configuration object. It checks if the configuration is verified before
creating the button. If the configuration is not verified, the function
returns undefined. The button type determines the style of the button:
rounded-square, slab, or transparent.

* feat: implement button container creation function

This function creates a container element for a button, allowing the
inclusion of an icon, text, and various attributes such as ID, class
name, and event listeners. It uses helper functions from the utilities
module to set attributes and events for the container element.

* feat: implement button removal function

This function removes a button element from the DOM based on the
provided configuration. It utilizes strict mode for improved code
quality and reliability.

* fix: modify and relocate events error message

Ensure early return in the if statement when events are not present in
the configuration. This adjustment improves code clarity and adheres to
the expected behavior. Additionally, relocate the error message handling
to the `button-create-container` file for better organization within the
codebase.

* refactor: add parameters to this.config in Button class

Due to changes in the configuration verification utility, parameters
needed to be updated in this.config at condition. Added this.name to
make the parameters more readable and ensure proper initialization.

* refactor: move helper function to main function

The `button-create` file had a helper function `button-create-container`.
Merged them into one file for better file organization within the
components folder. This change helps in tracking related functions more
effectively.

* fix: add 'button' parameter in 'button-create'

Updated `button-create` by adding the 'button' parameter due to changes
in the configuration verifier. This ensures the function operates with
the correct parameters.

* fix: separate 'text' from other config properties

Set 'text' to let instead of const to accommodate 'rounded-square' type
of button, which forces such buttons to have no 'text'. This change
ensures that the 'text' can be modified in the switch statement even if
explicitly included in the config properties. Keeping other properties
as const prevents unintended changes, maintaining stability.

* fix: change icon wrapper to i element from div

Ensure the icon is wrapped in an `i` element instead of a `div` for
proper icon display and alignment according to standard practices.

* feat: add tests for Button component

Introduce tests to validate the functionality of the Button component
methods. These tests provide assurance regarding the reliability and
correctness of the methods implemented within the component.

* refactor: update import paths for module resolution

Updated import paths in component files to use module resolution aliases
defined in jsconfig.json. This change improves code readability and
maintainability by replacing relative paths with aliases.

* fix: separate event setting from button creation

Fixes the bug of not setting events on a button because the button is
not yet created or appended to the DOM. Event setting relies on the
element's ID in the DOM. Separated event setting into another method to
address this issue. Additionally, return `this` in methods where
chaining is necessary.

* refactor: merge files into one

Combine multiple files into a single file to reduce unnecessary module
creation. This change simplifies navigation and improves codebase
organization.

* test: merge test files into one

Combine multiple test files into a single test file to reduce
unnecessary module tests. This change simplifies navigation and improves
codebase organization.

* style: expand print width to 100 characters

Adjusted code formatting to adhere to a maximum print width of 100characters, improving readability and consistency across the codebase.
@chessurisme chessurisme mentioned this pull request Jun 18, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant