Skip to content

Consider Switching from String-based CSS to JavaScript Object Syntax for Styles. #41

@SKRR6773

Description

@SKRR6773

Hi, I’ve been working with the Adapter class and appreciate the way it isolates styles for components. However, I’d like to share some feedback about the current string-based CSS approach:

  1. Hard to Write and Debug: Writing styles as strings can feel unintuitive. Without auto-complete or syntax checking, it’s easy to make mistakes, and catching them often only happens at runtime.

  2. Lack of Integration with Tools: IDE features like IntelliSense, auto-complete, and TypeScript support are unavailable for string-based CSS. These are tools I rely on heavily to code efficiently.

  3. Doesn’t Feel Like JavaScript: Modern JavaScript often uses object-based styles, where properties like background-color are converted to camelCase (backgroundColor). It’s cleaner, aligns with JavaScript conventions, and is easier to work with in dynamic contexts.

For example, instead of this:

const cardStyle = `
  display: block;
  min-height: 5rem;
  width: 100%;
  color: red;
`;

I’d prefer this:

const cardStyle = {
  display: "block",
  minHeight: "5rem",
  width: "100%",
  color: "red",
};

This approach:

Makes styles easier to write and maintain.

Allows tools like auto-complete and type checking to catch errors early.

Aligns better with the JavaScript ecosystem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions