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

Refactor Style Handling to Use CSS Object Types #6

Merged
merged 2 commits into from
Feb 4, 2024

Conversation

Dave-lab12
Copy link
Owner

Description

This PR transforms the existing string-based CSS style handling to a more robust and type-safe object-based approach. By leveraging TypeScript and CSS types from the csstype package

Before

canvasStyle: "border:10px solid red;position:fixed;top:0;left:0;zIndex:10";

After

canvasStyles: { border: "10px solid red", position: "fixed", top: "0", left: "0", zIndex: "10" };

Motivation

The transition to object-based CSS style handling is driven by several key objectives:

  • Improve Type Safety: By leveraging TypeScript's capabilities alongside csstype, we aim to reduce runtime errors. This approach allows us to catch incorrect CSS properties at compile time, minimizing common styling mistakes and enhancing the overall robustness of our code.

  • Enhance Developer Experience: Adopting an object-based approach for styles not only provides autocomplete suggestions for CSS properties and values, improving developer efficiency, but also makes the code more readable and maintainable. This change facilitates easier debugging and style adjustments.

  • increase Flexibility: The new styling approach simplifies the process of dynamically modifying styles. Developers can now easily merge default styles with customizations, providing greater control over the appearance of elements without the risk of unintentionally overriding other inline styles. Previously, attempting to add or modify a single style property could result in the loss of all other inline styles due to how string-based styles were concatenated or replaced. This update ensures that styles can be adjusted or extended in a more granular and safe manner, preserving existing styles while applying new ones.

@Dave-lab12 Dave-lab12 added bug Something isn't working enhancement New feature or request labels Feb 4, 2024
@Dave-lab12 Dave-lab12 merged commit b1622d7 into main Feb 4, 2024
2 checks passed
@Dave-lab12 Dave-lab12 deleted the feat/better-api-for-styles branch February 4, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant