Hi Fliers! The PatternFly team would like to ask your opinion on a couple of foundational approaches to the way we author CSS and allow for customization of PatternFly components in your application. We’re proposing one of the two solutions below, weighing the pros and cons of each approach. There are impacts on the overall amount of code used, component CSS file size, ease of making customizations, consistency of custom property names, and likelihood of introducing breaking changes from upstream changes.
In an effort to be transparent and provide the greatest value to PatternFly consumers, we’re curious which of these methods you would prefer as a developer implementing and maintaining the PatternFly design system in your application.
Option 1. Consolidating shared values in a component to a single variable that is used for multiple values in the component.
.pf-c-button {
--pf-c-button--PaddingY: var(--pf-global-spacer--sm);
--pf-c-button--PaddingX: var(--pf-global-spacer--lg);
--pf-c-button--BorderWidth: var(--pf-global-borderWidth--sm);
--pf-c-button--BorderColor: var(--pf-global-borderColor--primary);
padding: var(--pf-c-button--PaddingY) var(--pf-c-button--PaddingX);
&:hover,
&:focus,
&:active {
border: var(--pf-c-button--BorderWidth) solid var(--pf-c-button--BorderColor);
}
Pros
- Less code.
- Easier to make changes to multiple properties that share a common value.
- Lower file size**.
- Encourages more design consistency.
Cons
- Less consistent variable names.
- Greater potential for introducing breaking changes if, for example, PatternFly chooses to update the vertical spacing and change
--pf-c-button--PaddingY
to--pf-c-button--PaddingTop
and--pf-c-button--PaddingBottom
to support separate values for the top and bottom padding. - Less customizable, assuming you want to customize something that isn’t represented as a variable.
Option 2. Create a unique variable to use as the value for each property.
.pf-c-button {
--pf-c-button--PaddingTop: var(--pf-global-spacer--sm);
--pf-c-button--PaddingBottom: var(--pf-global-spacer--sm);
--pf-c-button--PaddingLeft: var(--pf-global-spacer--lg);
--pf-c-button--PaddingRight: var(--pf-global-spacer--lg);
--pf-c-button--hover--BorderWidth: var(--pf-global-borderWidth--sm);
--pf-c-button--hover--BorderColor: var(--pf-global-borderColor--primary);
--pf-c-button--focus--BorderWidth: var(--pf-global-borderWidth--sm);
--pf-c-button--focus--BorderColor: var(--pf-global-borderColor--primary);
--pf-c-button--active--BorderWidth: var(--pf-global-borderWidth--sm);
--pf-c-button--active--BorderColor: var(--pf-global-borderColor--primary);
padding: var(--pf-c-button--PaddingTop) var(--pf-c-button--PaddingRight) var(--pf-c-button--PaddingBottom) var(--pf-c-button--PaddingLeft);
&:hover {
border: var(--pf-c-button--hover--BorderWidth) solid var(--pf-c-button--hover--BorderColor);
}
&:focus {
border: var(--pf-c-button--focus--BorderWidth) solid var(--pf-c-button--focus--BorderColor);
}
&:active {
border: var(--pf-c-button--active--BorderWidth) solid var(--pf-c-button--active--BorderColor);
}
Pros
- More customizable.
- Less likelihood of introducing breaking changes if PatternFly changes a variable’s value.
- More consistent variable names.
Cons
-
More code.
-
Larger file size**.
-
More difficult to maintain, assuming PatternFly or a consumer wants to update, for example,
:hover
,:focus
, and:active
states at once to have a different (but the same between the states)border-width
and/orborder-color
. -
Allows for more/easier deviation from PatternFly’s design.
-
File size improvements vary per component, but we expect on average around a 20% improvement per component.
Here are examples of some of the more noteworthy file size improvements. (Note: this is the size of non-minified CSS):
- Card - from 2.1k to 1.4k (savings of 0.7k, or 67%)
- Nav - from 21k to 11k (savings of 10k, or 54%)
- Button - from 16k to 8k (savings of 8k, or 50%)
- Content - from 12k to 8k (savings of 4k, or 67%)
For context, the package size is currently about 347k, or 291k when minimized. We plan to make the package available without the utility classes, which brings the size to 240k, or 202k when minimized.