Skip to content

Commit 3b2c1f8

Browse files
committed
Add more clarity to the longhand / shorthand section
1 parent 9abc5dd commit 3b2c1f8

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

  • frontend/compose-html-ext/src/jsMain/kotlin/com/varabyte/kobweb/compose/css

frontend/compose-html-ext/src/jsMain/kotlin/com/varabyte/kobweb/compose/css/CONTRIBUTING.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,20 @@ for developers who need to quickly jump to the link to understand the property's
7373
---
7474
### Every **non-longhand** CSS style property should have a corresponding sealed interface
7575

76-
Some CSS properties are called *shorthand* and some are called *longhand*. A shorthand property is one that is a
77-
grouped representation of several inner properties, themselves called longhand properties.
76+
Some CSS properties are called *shorthand* and some are called *longhand*. Many CSS properties are neither.
7877

79-
For example, `margin-inline` is a shorthand property for `margin-inline-start` and `margin-inline-end`.
78+
A shorthand property is one that is a grouped representation of several inner properties, themselves called longhand
79+
properties.
80+
81+
If you look at the [Kobweb CSS checklist](https://docs.google.com/spreadsheets/d/1Uu2diibyOzDFPgzzM8BWlw4B9_CTDBACv_1E_tsXbp8),
82+
everything in the second and third columns are longhand properties. Anything in the first column that parents properties
83+
in the second column is a shorthand property.
84+
85+
For example, `margin-inline` is a shorthand property for `margin-inline-start` and `margin-inline-end`. Conversely,
8086
`margin-inline-start` and `margin-inline-end` are longhand properties.
8187

88+
Meanwhile, `appearance` is just a regular CSS property, neither shorthand nor longhand.
89+
8290
Many longhand properties are simple primitive values (such as `border-width`).
8391

8492
There are hundreds of these longhand properties (`border` alone has about fifty of them), so we've decided not to add
@@ -93,22 +101,38 @@ But we require types for shorthand properties and normal properties as a pre-req
93101
sealed interface StyleExample /*...*/
94102
```
95103

104+
##### Avoid
105+
96106
```kotlin
97-
98-
sealed interface MarginInlineEnd /* ... */
107+
// margin-inline-end is a longhand property and shouldn't provide an
108+
// interface for it.
109+
sealed interface MarginInlineEnd /* ... */
110+
111+
// Instead, just handle this with a StyleScope extension method / methods
112+
// that accept relevant primitive values. We talk more about these methods
113+
// much later in the document.
114+
fun StyleScope.marginInlineEnd(value: CSSLengthOrPercentageNumericValue) {
115+
property("margin-inline-end", value)
116+
}
99117
```
100118

101-
Even if the property is 99% of the time a simple integer value (e.g. `column-count`), we still need to support users
102-
being able to pass in global values (e.g. `ColumnCount.Inherit`), so we will always need a container type for every
103-
single property type.
119+
Even if the (non-longhand) property is a simple integer value 99% of the time (e.g. `column-count`), we still need to
120+
support users being able to pass in global values (e.g. `ColumnCount.Inherit`). For this reason, we always need to
121+
create some kind of container type to hang those global values on, thus here we chose a sealed interface.
104122

105123
We seal the interface to prevent users from inheriting it. Our intention is for this to be self-contained type that only
106124
we control.
107125

126+
Longhand properties technically can also support global keywords (e.g. `margin-inline-end: inherit` is valid!) but our
127+
expectation for now is the need for this is going to be so rare that it's not worth creating tons of extra code for it.
128+
If a user *really* needed to do this, they can always use `property("margin-inline-end", "inherit")` as a workaround.
129+
We may revisit this decision later.
130+
108131
#### Exception
109132

110-
If a longhand property is notably complex, like several of the `animation` longhand properties are, then you can of
111-
course introduce classes for those cases. But we do not plan to support most of them at this time.
133+
If a longhand property is notably complex and not simply primitive values, like several of the `animation` longhand
134+
properties are, then you can of course introduce classes for those cases. But we do not plan to support most of them at
135+
this time.
112136

113137
---
114138
### Every interface should implement `StylePropertyValue`

0 commit comments

Comments
 (0)