aesthetic-suite / framework

🎨 Aesthetic is an end-to-end multi-platform styling framework that offers a strict design system, robust atomic CSS-in-JS engine, a structural style sheet specification (SSS), a low-runtime solution, and much more!
https://aestheticsuite.dev
MIT License
203 stars 5 forks source link

Overwriting styles vs Extending styles #2

Closed milesj closed 7 years ago

milesj commented 7 years ago

Aesthetic aims to solve the following two ownership scenarios:

The first scenario is rather easily solved without much hassle. The second scenario is what Aesthetic tries to solve via the static setStyles method on a wrapped component (provided by a styler function).

Now for the comparison. I will use Toolkit components as an example, even though they don't use Aesthetic. Just assume it does use Aesthetic, and defines external classes as its style, like so:

// toolkit/components/Accordion
export default style({
  accordion: 'accordion',
  accordion__collapsible: 'is-collapsible',
  accordion__multiple: 'is-multiple',
}, {
  styleName: 'ToolkitAccordion',
  lockStyling: false,
})(Accordion);

Both approaches need to satisfy the following criteria:

Overwriting

Overwriting allows us to change the styles without having to create a new local component. The original styles can be referenced by using style functions.

// bootstrap.js
import Accordion from 'toolkit/components/Accordion';

Accordion.setStyles({
  accordion: { ... },
  accordion__collapsible: { ... },
  accordion__multiple: { ... },
});

// App.js
import Accordion from 'toolkit/components/Accordion';

<Accordion />

Pros

Cons

Extending

Extending allows us to change the styles but creates a new local component in the process (another layer of composition).

// components/Accordion.js
import Accordion from 'toolkit/components/Accordion';

export default Accordion.extendStyles({
  accordion: { ... },
  accordion__collapsible: { ... },
  accordion__multiple: { ... },
});

// App.js
import Accordion from '../components/Accordion';

<Accordion />

Pros

Cons

milesj commented 7 years ago

I'm leaning towards switching to extending so you can do things like:

import BaseButton from 'toolkit/components/Button';

export const Button = BaseButton.extendStyles({
  button: { ... },
});

export const PrimaryButton = Button.extendStyles({
  button: { ... },
});

export const SecondaryButton = Button.extendStyles({
  button: { ... },
});
milesj commented 7 years ago

Went with the extending styles approach.