[css-variables-2] Custom shorthands with `@property`
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reviewing the proposal in this issue and the related CSSWG issue #7273, then examine the surrounding discussion for constraints on custom shorthands, constituent properties, syntax, and keyword behavior. Done means reaching a resolved CSSWG design or specification decision, rather than making a localized code edit.
Written by the indexing model from the issue text.
Description
Context :
Currently there is no way to reuse small groups of declarations (keys and values) in multiple styles without creating a style rule for them.
.want-to-reuse {
color: hotpink;
padding: 15px;
display: flex;
}
To apply this to multiple components you need to alter your markup.
Or you need to copy/paste the declarations to each style rule.
Mixins are often used to work around this.
I know mixins will never be a thing in native CSS and maybe the same reasons behind that apply to this proposal.
@mixin some-mixin {
color: hotpink;
padding: 15px;
display: flex;
}
selector {
@include some-mixin;
}
Custom properties also help to some extend because they allow values to be re-used.
Naming conventions help to group sets of values.
:root {
--some-color: purple;
--some-padding: 20px;
--some-display: flex;
--fancy-color: hotpink;
--fancy-padding: 15px;
--fancy-display: flex;
}
Proposal :
Can custom shorthands be defined through @property?
syntaxmust match the declared constituent properties- keywords like
initialwork exactly like they work for native shorthands
I included padding in the example but maybe shorthand in shorthands have issues?
@property --some-shorthand {
syntax: "<color>" "<length>" "<ident>";
constituent-properties: color padding display;
values:
default / purple 20px flex,
fancy / hotpink 15px flex;
}
.foo {
--some-shorthand: fancy;
}
Is equivalent to :
.foo {
color: hotpink;
padding: 15px;
display: flex;
}
Set values of constituent properties :
.foo {
--some-shorthand: green 10px block;
}
This is somewhat related to https://github.com/w3c/csswg-drafts/issues/7273 as it allows similar patterns when styling elements.
- Dominant language
- Bikeshed
- Stars
- 4.9k
- Forks
- 816
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 24
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from w3c/csswg-drafts
-
Agenda+ css-sizing-4 css-values-5
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
w3c/csswg-drafts#14502 · 1 reaction ·
-
css-values-5 editorial Needs Edits
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
w3c/csswg-drafts#14498 · 2 comments ·
-
css-overflow-4 topic: line-clamp
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
w3c/csswg-drafts#14485 · 1 comment ·
-
Administrative Tracker css-values-4
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
w3c/csswg-drafts#14482 · 4 comments · 1 reaction ·
-
css-values-5 Needs Edits
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
w3c/csswg-drafts#14466 ·
All issues in w3c/csswg-drafts
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
tvOS
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bvaughn/react-resizable-panels#751 · 1 comment ·
-
www.wiwo.de OpenN: AdGuard Browser Extension P3: Medium T: Annoyance
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AdguardTeam/AdguardFilters#242026 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 92/100