Sentiment Tokens
Why?
Ensure swapability of different sentiments on a component.
Sentiment tokens are used to add visual clarity to feedback, or to actions.
These will include items such as 'Positive' (for actions) or 'Success' (for feedback), 'Danger' or 'Error' (likewise) and so on.
Again, these are commonly found in a structured semantic collection as follows:
Primitives/Green/300Primitives/Green/1100Primitives/Green/400Primitives/Green/1000Primitives/Green/500Primitives/Green/900Primitives/Red/300Primitives/Red/1100Primitives/Red/400Primitives/Red/1000Primitives/Red/500Primitives/Red/900Again, note the repetition. The semantic tokens are structured in such a way that it looks like one ought to be able to swap them out, but for a fully featured button there are nine separate variables (foreground, background, border x default, hover, active) that are needed to be set correctly.
<div class="widget-positive">Positive</div>
<div class="widget-negative">Negative</div>.widget-positive {
background-color: var(--semantics-sentiment-positive-background);
}
.widget-negative {
background-color: var(--semantics-sentiment-negative-background);
}The sentiment token, building optionally on top of behavioural tokens, fixes this.
Semantics/Sentiment/Background/PositiveSemantics/Sentiment/Background/NegativeSemantics/Sentiment/Foreground/PositiveSemantics/Sentiment/Foreground/NegativeSemantics/Sentiment/Border/PositiveSemantics/Sentiment/Border/Negative<div class="container-sentiment sentiment-positive">Positive</div>
<div class="container-sentiment sentiment-negative">Negative</div>.sentiment-positive {
--semantics-sentiment-background: var(
--semantics-sentiment-positive-background
);
}
.sentiment-negative {
--semantics-sentiment-background: var(
--semantics-sentiment-negative-background
);
}
.container-sentiment {
background-color: var(--semantics-sentiment-background);
}Note now the container-sentiment and sentiment-* classes could be reused anywhere else to achieve an easily swappable sentiment. Adding a new sentiment is as simple as adding the new definition in sentiment.css, and all components using container-sentiment will automatically get support.